+ Reply to Thread
Results 1 to 7 of 7

Loop through group of values, calculate a total

  1. #1
    Registered User
    Join Date
    12-08-2011
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    26

    Arrow Loop through group of values, calculate a total

    The Issue:
    I have a fairly large excel file (2000+ rows) that contains groups of values in column A (that vary in length), then numerical values in columns C and D that are associate with those values. I need to go through each of these groups and calculate a total based on adding all the values for that group that are located in columns C and D.

    The one nice thing is that the values of the groups are all together.

    The Problem:
    My problem is that I'm having a tough time trying to figure an algorithm to compute the proper total. In Java I could use maps and lists and associate it through creating dynamic classes. VBA is a bit different.

    Any help would be greatly appreciated.

    Attached is a sample workbook. Sheet 1 contains the data. Sheet 2 is where I'm trying to print the summary data and what I'm wishing the data to look like.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: Loop through group of values, calculate a total

    It's kind of confusing trying to figure out how would you produce the Sheet2 from Sheet1.
    Can you please go to Sheet2 and type real values reflecting what is in Sheet1 then reUpload the file?
    Regards,
    Khaled Elshaer
    www.BIMcentre.com

    Remember To Do the Following....
    1. Thank those who have helped you by clicking the Star below their post.
    2. Mark your post SOLVED if it has been answered satisfactorily:
    • Select Thread Tools (on top of your 1st post)
    • Select Mark this thread as Solved

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

    Re: Loop through group of values, calculate a total

    I did this with a pivot table:

    Please Login or Register  to view this content.
    This is what you are after?
    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.

  4. #4
    Registered User
    Join Date
    12-08-2011
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Loop through group of values, calculate a total

    abousetta,
    In a way yes. I had considered pivot tables, but I need just one value for each group. So A should have a value of 59.285, B should have a value of 51.71.

    Sheet2 then holds a department number for each group, and I take the total for each group for their department. This is easily calculated using pivot tables, and that's what I will do on sheet2

    I just am a bit stumped on how to loop through sheet 1 and get a single value for Group A, Group B, Group C, etc until the end of a 2,000 row sheet from Sheet1.

    Does that make more sense? Or do I need to clarify more?

  5. #5
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: Loop through group of values, calculate a total

    Here you go:

    Please Login or Register  to view this content.
    Last edited by Kelshaer; 03-07-2012 at 01:43 PM.

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

    Re: Loop through group of values, calculate a total

    The fastest way is to feed the whole range into an array and calculate everything in memory...

    having said that, I still doesn't understand how you got a value of 59.285 for A and 51.71 for B.

    If you could explain a bit more, maybe we can expedite the solution.

  7. #7
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: Loop through group of values, calculate a total

    Quote Originally Posted by abousetta View Post
    The fastest way is to feed the whole range into an array and calculate everything in memory...

    having said that, I still doesn't understand how you got a value of 59.285 for A and 51.71 for B.

    If you could explain a bit more, maybe we can expedite the solution.
    The numbers are the sum of columns C & D in Sheet1

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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