+ Reply to Thread
Results 1 to 5 of 5

Combine muliple rows into one based on criteria

  1. #1
    Registered User
    Join Date
    11-08-2007
    Posts
    1

    Combine muliple rows into one based on criteria

    Hello,

    I am trying to cycle though 0-200 rows of data each with a product key and demand data. I need an output of one row for each key with a total of the demand data.

    Example:

    A spreadsheet like this one:

    product demand 1 demand 2 ...
    -----------------------------------------------
    1616 50 50
    1616 50 50
    1617 25 25
    1616 100 100
    1617 50 50

    total 275 275


    become one like this one:

    product demand 1 demand 2 ...
    -----------------------------------------------
    1616 200 200
    1617 75 75

    total 275 275



    the use of a VBA macro is preferred because I already have one doing other things to get the data, so I can just incorporate it into the current one.

    I have a decent grasp of VBA and good knowledge of excel.

    Any ideas on how to go about this? THANKS!

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    Whilst you might prefer a macro, I think the easiest option is to use a pivot table. Follow the Wizard, put Product in the row field and Sum of demand1 & Sum of demand 2 in the data field.

  3. #3
    Forum Contributor
    Join Date
    10-11-2007
    Location
    Sweden
    MS-Off Ver
    365
    Posts
    251
    I hope this can help you!

    Sum automatically specific posts in a list

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Perhaps this UDF would help. It looks down the compareRange and if the entry in that column matches the compareValue, adds the sum of all entries on that row of the SumRange to the result and then looks at the next row.
    For your example, if your product is in Column A and the demands are in B & C, =SumRangeIf(A:A,1616, B:C) and =SumRowsIf(A:A, 1617, B:C) would be the syntax.

    Please Login or Register  to view this content.
    Even if you don't call this as a spreadsheet function, it might be helpful writting the macro you want. About that macro, on which sheet is the Product and demand data you want to process (are there only two demand columns or is the column count variable) and where do you want the results?

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525
    Assuming data are in Sheet1, outputting in Sheet2
    try
    Please Login or Register  to view this content.

+ 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