+ Reply to Thread
Results 1 to 4 of 4

How to find conditional cumulative sums in an excel table using VBA macro

  1. #1
    Registered User
    Join Date
    03-18-2016
    Location
    Cambridge, Mass
    MS-Off Ver
    2013
    Posts
    5

    How to find conditional cumulative sums in an excel table using VBA macro

    Let's say I have two columns.
    3.5463 11
    4.5592 12
    1.6993 111
    0.92521 112
    1.7331 121
    2.1407 122
    1.4082 1111
    2.0698 1112
    2.3973 1121
    2.4518 1122
    1.1719 1211
    1.153 1212
    0.67139 1221
    0.64744 1222
    1.3705 11111
    0.9557 11112
    0.64868 11121

    0.7325 11211
    0.58874 11212
    0.86673 11221
    0.17075 11222
    0.64026 12111
    0.80229 12112

    0.43422 12122
    1.0405 12211
    0.63376 12212
    0.56491 12221
    0.34626 12222
    0.81631 111111
    0.91837 111112
    0.70013 111121
    0.87384 111122
    1.1474 111211

    0.47411 111221
    0.12249 111222
    0.56728 112111
    0.88169 112112
    0.14509 112121

    0.68655 112211
    0.36274 112212


    1.1652 121111
    0.99314 121112
    0.42024 121121
    0.23937 121122




    1.0346 122111
    0.64642 122112
    0.15632 122121
    0.41725 122122
    0.40793 122211

    In the first column, there is a number. With every one of those numbers, in the second column, is an associated ID. Now, there are some blank rows that do not contain any numbers in them.

    Define one of these numbers to be a "daughter" of another number if the ID of the first number is the same as the ID of the second, with an extra digit on the end. For example, both IDs 11211 and 11212 are daughters of 1121, because the ID of 1121 has an extra digit, either a 1 or a 2, added onto the end to form the ID of its daughters. Thus, 1121 is the parent of both 11211 and 11212.

    Here is what I want the macro to do. It must output a third column which contains, for every row, a cumulative sum of the number of the first column in that row, plus the parent number of that number, and the parent number of the parent number, etc. all the way up until it reachers either 11 or 12. It will begin by simply outputting the numbers in column 1 for 11 and 12 in the third column. Then, in a loop beginning with 111, it will add up the cumulative sum of every row (the number in that row plus the third column output of the parent), only if that row has a number and an id, and only if the parent exists and has an output in column 3. So for example, the number in the 3rd column of the row with ID 11222 should be the number in column 1 of that row, plus that of 1122, plus that of 112, plus that of 11. So, 0.17075+2.4518+0.92521+3.5463, or 7.09406. However, if you try to do this for ID 111221, you will notice that the row where the parent 11122 should be is empty. Thus, the parent does not exist, and no value will be outputted in column 3 for 111221.

    I would greatly appreciate it if someone has some time on their hands to code up this VBA macro for me.

    Thanks

  2. #2
    Forum Contributor
    Join Date
    05-02-2015
    Location
    calgary alberta
    MS-Off Ver
    2012
    Posts
    205

    Re: How to find conditional cumulative sums in an excel table using VBA macro

    Its going to be best if you paste a copy of your workbook

  3. #3
    Registered User
    Join Date
    03-18-2016
    Location
    Cambridge, Mass
    MS-Off Ver
    2013
    Posts
    5

    Re: How to find conditional cumulative sums in an excel table using VBA macro

    3.5463 11
    4.5592 12
    1.6993 111
    0.92521 112
    1.7331 121
    2.1407 122
    1.4082 1111
    2.0698 1112
    2.3973 1121
    2.4518 1122
    1.1719 1211
    1.153 1212
    0.67139 1221
    0.64744 1222
    1.3705 11111
    0.9557 11112
    0.64868 11121

    0.7325 11211
    0.58874 11212
    0.86673 11221
    0.17075 11222
    0.64026 12111
    0.80229 12112

    0.43422 12122
    1.0405 12211
    0.63376 12212
    0.56491 12221
    0.34626 12222
    0.81631 111111
    0.91837 111112
    0.70013 111121
    0.87384 111122
    1.1474 111211

    0.47411 111221
    0.12249 111222
    0.56728 112111
    0.88169 112112
    0.14509 112121

    0.68655 112211
    0.36274 112212


    1.1652 121111
    0.99314 121112
    0.42024 121121
    0.23937 121122




    1.0346 122111
    0.64642 122112
    0.15632 122121
    0.41725 122122
    0.40793 122211

  4. #4
    Registered User
    Join Date
    03-18-2016
    Location
    Cambridge, Mass
    MS-Off Ver
    2013
    Posts
    5

    Re: How to find conditional cumulative sums in an excel table using VBA macro

    That's it. Just two columns

+ 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. Needing some help with cumulative sums over different date blocks
    By Murphyslaw in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-16-2015, 03:57 AM
  2. [SOLVED] Isolate sum from cumulative sums in a column
    By nrrrrb in forum Excel General
    Replies: 4
    Last Post: 07-29-2013, 10:44 AM
  3. [SOLVED] Cumulative sums
    By kipronopaul in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-11-2012, 08:21 AM
  4. conditional sums in a filtered table?
    By Ari88 in forum Excel General
    Replies: 4
    Last Post: 09-15-2011, 03:45 PM
  5. cumulative sums
    By Icarni in forum Excel General
    Replies: 6
    Last Post: 11-02-2009, 10:41 AM
  6. Help regarding cumulative sums
    By karaflas01 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-30-2008, 09:30 AM
  7. [SOLVED] Cumulative Sums in Pivot Tables
    By Laura in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-11-2006, 02:00 PM

Tags for this Thread

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