+ Reply to Thread
Results 1 to 7 of 7

Cumulative sum using Do Until ... Loop

  1. #1
    Registered User
    Join Date
    11-17-2017
    Location
    POLAND
    MS-Off Ver
    2013
    Posts
    25

    Cumulative sum using Do Until ... Loop

    Hi,

    I want to calculate sum of each amount from Input.xlsx file, depending on the aging calculate in column L.

    For now I have this:

    Please Login or Register  to view this content.
    The problem is that I want to each sum (sum0, sum 30, etc.) contains the cumulative sum for each aging bucket. So later when I will want to refer to sum30 it will contains all amounts summed together.
    For now each sum remembers only sum for each row one at a time.

    What do you think about this?
    Attached Files Attached Files

  2. #2
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Cumulative sum using Do Until ... Loop

    Hi mati_WAR, try this:
    Please Login or Register  to view this content.
    Since the tests ascend in value, there's no need to check the "Floor"; previous buckets will claim any smaller values.
    Last edited by leelnich; 11-28-2017 at 10:00 AM.
    Clicking the Add Reputation star below helpful posts is a great way to show your appreciation.
    Please mark your threads as SOLVED upon conclusion (Thread Tools above Post # 1). - Lee

  3. #3
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Cumulative sum using Do Until ... Loop

    Like leelnich I'd go with Select Case.

    As well, instead of looping through cells directly. It's much faster to commit range to array and loop through array in memory.
    Please Login or Register  to view this content.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  4. #4
    Registered User
    Join Date
    11-17-2017
    Location
    POLAND
    MS-Off Ver
    2013
    Posts
    25

    Re: Cumulative sum using Do Until ... Loop

    Thank you both for help :-)

    In fact, Select Case makes much more sense in this case.

    Regarding If method I have also updated my part of code to be more efficient:

    Please Login or Register  to view this content.

  5. #5
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Cumulative sum using Do Until ... Loop

    Mati, post #4 looks like post #1. Did you paste the right code? In any case (lol), if you are satisfied with the answer, please go to Thread Tools (up top) and mark your thread SOLVED. Thanks! - Lee

  6. #6
    Registered User
    Join Date
    11-17-2017
    Location
    POLAND
    MS-Off Ver
    2013
    Posts
    25

    Re: Cumulative sum using Do Until ... Loop

    Quote Originally Posted by leelnich View Post
    Mati, post #4 looks like post #1. Did you paste the right code? In any case (lol), if you are satisfied with the answer, please go to Thread Tools (up top) and mark your thread SOLVED. Thanks! - Lee
    Yeah, it's almost the same. I delete "WorksheetFunction.sum" from the code and also "End if" was in incorrect place, because it caused freezing of the macro :-D

  7. #7
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Cumulative sum using Do Until ... Loop

    Got it, thanks for the rep!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Cumulative Sum
    By manisai in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-14-2015, 02:21 AM
  2. Cumulative
    By mfond1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-24-2014, 08:29 PM
  3. Formulas for cumulative value and cumulative %
    By Brotein in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 10-28-2013, 07:19 PM
  4. [SOLVED] Copy dynamically changing column and Paste using VBA Loop (Loop within Loop)
    By nixon72 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2013, 12:46 PM
  5. [SOLVED] Cumulative End If ?
    By ZuluNation in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-17-2012, 06:31 AM
  6. [SOLVED] Cumulative Sum
    By Arvi Laanemets in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-06-2005, 04:05 AM
  7. Cumulative Sum
    By kk in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 PM

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