+ Reply to Thread
Results 1 to 5 of 5

Need a looping macro with dynamic conditions

  1. #1
    Registered User
    Join Date
    07-21-2011
    Location
    Missouri
    MS-Off Ver
    Excel 2007
    Posts
    16

    Need a looping macro with dynamic conditions

    I need a ‘looping’ macro (relative) that sums cell values based on adjacent cell contents.

    With the cursor on cell B4, for instance, start the macro.
    It sets the contents of C4 as the compare-with variable, and sums the values of D4 through Dr, where r is the last row where Cr contents equal the compare-with variable, and the sum appears on B4.

    At that point, it looks at Cr+1, and if not empty, replaces the ‘compare-with’ variable its contents. It now sums the values of Dr+1y through Dr+1y, where y is the last row where the contents of Cr+1y are the same as the newer compare-with variable, and the sum appears on Br+1.

    Repeats until there are no values.

    BTW, the list is sorted by the values in column C, so the compare-with values are grouped.

    Please let me know if I can add anything to my explanation.

    Thx!

    Nando
    Last edited by Nando01; 07-25-2011 at 02:05 PM. Reason: add one line

  2. #2
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Need a looping macro with dynamic conditions

    your explanation looks quite good but it should be better if you will add any workbook with dummy data.

    Best Regards

  3. #3
    Registered User
    Join Date
    07-21-2011
    Location
    Missouri
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Need a looping macro with dynamic conditions

    I wasn't sure how to attach a file. I'll try - - -
    Looks like it worked.
    In this example, I manually inserted the SUM functions where I would like the macro to do it.

    Thx!

    Nando.
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Need a looping macro with dynamic conditions

    I tape macro for automate insert SUM formula

    macro in sheet1 code, probably there is simplier way but I create following:
    Please Login or Register  to view this content.
    Best Regards
    MaczaQ
    Last edited by MaczaQ; 07-22-2011 at 09:40 AM. Reason: I found error, now should be OK.

  5. #5
    Registered User
    Join Date
    07-21-2011
    Location
    Missouri
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Need a looping macro with dynamic conditions

    maczaq -

    That worked just fine - what I needed!

    Thx!!!!

    Alex

+ 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