+ Reply to Thread
Results 1 to 11 of 11

Consolidate data

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Consolidate data

    I have a list that i am trying to consolodate.

    In colA i have an id-number. In colB i have hours worked.

    What i want to do is consolodate the list such that i have one row for each "id" and in column B i want the total hours worked for that "id".

    So my problem is i have a list like this

    ID Hours worked
    11 4.5
    11 4.0
    11 1.0
    12 8.0
    13 4.0
    14 1.0
    14 3.0
    14 4.0
    14 5.0
    15 8.0

    What i want is to consolodate the list such that i have the following

    ID Hours worked
    11 9.5
    12 8.0
    13 4.0
    14 13.0
    15 8.0

    Anyone have idea as to the best way to do this via VBA? Ideally i would like to keep the original list intact and create a separate consolodated list.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Consolidate data

    I would suggest you click in the data and then Data > PivotTable.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Consolidate data

    Hi Welchs, the following should work pretty well. It inserts a unique list of ID's into column D and then the sums (using SUMIF formulas) into column E.
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: Consolidate data

    i need to do this via vba........

  5. #5
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: Consolidate data

    hi paul,

    just saw your post.........i will check

    thanks.

  6. #6
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: Consolidate data

    hi paul,

    yes this works great! Apparently i left out one important thing though.........the sheet this is occuring on is "hidden" so when i run your macro for a hidden sheet i get a runtime error.

  7. #7
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Consolidate data

    Ok, put this code into a standard module (VB Editor -> Insert -> Module) and change "Sheet2" to your hidden sheet's name. If you still get an error, is the hidden sheet also protected? You would have to unprotect it at the beginning of the macro, then re-protect it at the end.
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: Consolidate data

    this works! thanks.

  9. #9
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: Consolidate data

    Hi Paul,

    I was wondering if you coudl help with one more thing.

    ID Hours worked Name
    11 4.5 A
    11 4.0 A
    11 1.0 A
    12 8.0 B
    13 4.0 C
    14 1.0 D
    14 3.0 D
    14 4.0 D
    14 5.0 D
    15 8.0 E

    Suppose i had a name col such as the one above......how would i also get the name in the new list.

  10. #10
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Consolidate data

    I'd suggest not having a name column, and in a separate area of the worksheet/workbook have a list of ID's and their corresponding names (e.g. on Sheet7 in columns A and B). You could then use VLOOKUP to match the name to the correct ID's in column D on the main sheet.

    It's just a better way to store data, and keeps the file size smaller by not replicating data over and over.

  11. #11
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: Consolidate data

    ok...thanks.

    I learned a little with your script.........i was not considering anything like this. I was thinking about multiple loops.....anyway.....thanks.

+ 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