+ Reply to Thread
Results 1 to 15 of 15

Sum cells in a column and display in next column and repeat

  1. #1
    Registered User
    Join Date
    11-23-2011
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2007
    Posts
    14

    Sum cells in a column and display in next column and repeat

    Hi,
    I am trying to sum the rows in a column and if the sum exceeds 2400, then put the total in the cell in next column prior to it exceeding 2400.

    Once that is done, it repeats the same from the next row onward.

    I have attached the workbook with Before and After sheets. Hope I am able to explain myself.

    Thanks.
    Attached Files Attached Files
    Last edited by nileshrg; 11-30-2011 at 03:20 AM.

  2. #2
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Sum cells in a column and display in next column and repeat

    Hi,

    This code will do

    Please Login or Register  to view this content.
    Please take time to read the forum rules

  3. #3
    Valued Forum Contributor ffffloyd's Avatar
    Join Date
    05-20-2008
    Location
    Melbourne, VIC, Australia
    MS-Off Ver
    Office 365
    Posts
    243

    Re: Sum cells in a column and display in next column and repeat

    I have added a sheet to your workbook called Calculation. It does what you ask. See the added headings and their accompanying comments for an explanation. In brief:
    • column K keeps a running total;
    • column L keeps track of what the next number is going to be;
    • column M works out if there is even going to be a next number; and
    • column N says, "If the running total plus the next number exceeds the nominated maximum OR if there isn't going to be a next number then publish the total so far."
    You could actually put that logic in column B but, to keep all the complexities away from the main display, column B just says that if there is a number in column N then I'll show it here.
    Attached Files Attached Files
    _______________
    Floyd Emerson
    Business Intelligence Consultant
    Melbourne, Victoria, Australia

  4. #4
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Sum cells in a column and display in next column and repeat

    Maybe try this non-vba approach. In Cell B2 add this formula and drag down to the end

    Please Login or Register  to view this content.
    Hope this helps.

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  5. #5
    Registered User
    Join Date
    11-23-2011
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Sum cells in a column and display in next column and repeat

    Hi Steffen,

    I tried your code. It gives me the total after it has crossed 2400. I need to calculate the total just before it goes to 2400.

  6. #6
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Sum cells in a column and display in next column and repeat

    This will do

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-23-2011
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Sum cells in a column and display in next column and repeat

    Thanks Steffen. It works better but still it does not check for the last few cells. In the same example it does not show the total for last 3 values.

  8. #8
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Sum cells in a column and display in next column and repeat

    A variation on ffffloyds' method for finding the next value, and using SUMIF()

    Change the value in E1 to vary the results (Use the grouping button to hide the helper Columns)
    Attached Files Attached Files
    Last edited by Marcol; 11-29-2011 at 05:44 AM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  9. #9
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Sum cells in a column and display in next column and repeat

    That because it doesnt reach the cap, try this code
    Please Login or Register  to view this content.

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Sum cells in a column and display in next column and repeat

    Please Login or Register  to view this content.
    Last edited by snb; 11-29-2011 at 06:30 AM.



  11. #11
    Registered User
    Join Date
    11-23-2011
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Sum cells in a column and display in next column and repeat

    Hi Steffen,
    This works like a charm. i realized something weird. Pls correct me.
    When I use this code in a sample sheet it works fine but when i use it as a part of my entire code it recognizes variables "Total" and "cell" are not defined.

    Why so?

  12. #12
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Sum cells in a column and display in next column and repeat

    Thats because you have option explicit at the top.

    Add this at the top of the code

    Please Login or Register  to view this content.

  13. #13
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Sum cells in a column and display in next column and repeat

    @Steffen

    Please Login or Register  to view this content.
    is an overcomplicated way of writing:

    Please Login or Register  to view this content.
    But if you use specialcells(2), this test is redundant.
    Last edited by snb; 11-29-2011 at 06:36 AM.

  14. #14
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Sum cells in a column and display in next column and repeat

    Thank you snb

  15. #15
    Registered User
    Join Date
    11-23-2011
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Sum cells in a column and display in next column and repeat

    Thanks a ton all of you for providing both vba and non-vba solutions.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1