+ Reply to Thread
Results 1 to 11 of 11

Combine Rows with Calculation (Dupe in one column)

  1. #1
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Combine Rows with Calculation (Dupe in one column)

    What is the best way to combine rows where one column contains a duplicate field (in this case an order number) - and then one column is a dollar amount that needs to be summed.
    Basically each line is a line item on an order, and so the order number appears multiple times for each item. Want to combine the sales orders into one row with total sales.

    I have tried manually combine/group options in Excel and they don't work as intended.

    I tried kutools which has a very specific tool to do this but won't work if you have more than around 500 rows.

    I have columns A:BJ (a lot of columns)
    The Primary key item is in Column E (SalesOrder) and the Dollar amount is in Column BJ (TotalLineSalesPrice)
    I would really like to do diff things in some other rows besides take the first value but at this point I don't care about that I just want to combine the rows with same SalesOrder value and sum the TotaLineSalesPrice value.

    Is VBA the best way to do this? not sure why this has been so difficult for me - been fighting it for three weeks now.


    I really don't need all the columns so to simplify if we want to just say we have 4 columns and I can try to modify it from there.
    Order Date, Sales Order, Part Number, LinePrice

    Combine based on dupe in SalesOrder, and sum the LinePrice

    The closest thing I found was the Consolidate feature but this seems to only work when you just have two columns and not extra columns (or any extra columns will either sum also or just be blank)
    Last edited by NewYears1978; 05-18-2021 at 01:00 PM.

  2. #2
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Combine Rows with Calculation (Dupe in one column)

    Can you share a sample file as per the yellow banner above? Make sure to include the before and after views.

  3. #3
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: Combine Rows with Calculation (Dupe in one column)

    Quote Originally Posted by maniacb View Post
    Can you share a sample file as per the yellow banner above? Make sure to include the before and after views.
    Yes sorry - I always forget to do that on my initial post because it's sensitive data and I have to make a fake version, will do that now.
    Also there are so many columns that it's hard to read the fake data =D

    Sample attached.

    You can see the "duplicate" column to look at is SalesOrder and then the very last column is Summed, everything else just keeps the first value (for simplicity sake)

    Been struggling so much with Excel lately because these files have 800k rows and it is just not wanting to handle that much data
    Attached Files Attached Files
    Last edited by NewYears1978; 05-18-2021 at 02:35 PM.

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,345

    Re: Combine Rows with Calculation (Dupe in one column)

    One way...Assumes data is in order...
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by sintek; 05-19-2021 at 04:33 AM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  5. #5
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: Combine Rows with Calculation (Dupe in one column)

    I will try that, thank you. I really need to fully learn VBA - I can write some stuff but mostly it's piecing together things here and there!


    I got a type mismatch on this:
    Data = .Cells(1).CurrentRegion.Value: ReDim Temp(1 To UBound(Data, 1), 1 To UBound(Data, 2))
    Last edited by NewYears1978; 05-19-2021 at 02:28 PM.

  6. #6
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Combine Rows with Calculation (Dupe in one column)

    Here is another solution for you. This will create a 'Data' sheet where the results will be placed.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by maniacb; 05-19-2021 at 01:49 PM. Reason: Add file

  7. #7
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: Combine Rows with Calculation (Dupe in one column)

    That one gave me an error also after running awhile (I have a ton of rows) it then created the data tab and gave error which I accidentally closed.

    I am running it again to see if I can see the error again.

    Type mismatch:
    h(r, 33) = h(r, 33) + a(j, 33)
    Last edited by NewYears1978; 05-19-2021 at 02:48 PM.

  8. #8
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Combine Rows with Calculation (Dupe in one column)

    Try opening the file we provided and see if the file structure looks different from your working file. I assume all the column data in your working file is the same as the sample data you provided. The error implies that the data type in column 33("AG") is not a number, is it in your working data?

  9. #9
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Combine Rows with Calculation (Dupe in one column)

    I amended the code to only add when the value in column AG is a numeral. But if the number is being presented as text, you'll need to review that data column so as not to get inaccurate results. Also, ensure column AG is formatted as a number, not text.

    Please Login or Register  to view this content.

  10. #10
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,345

    Re: Combine Rows with Calculation (Dupe in one column)

    Quote Originally Posted by NewYears1978 View Post
    I got a type mismatch on this:
    Data = .Cells(1).CurrentRegion.Value: ReDim Temp(1 To UBound(Data, 1), 1 To UBound(Data, 2))
    Does not happen with your sample file and upload in Post 4...Perhaps your actual file setup is not exactly the same as sample?
    Last edited by sintek; 05-20-2021 at 03:49 AM.

  11. #11
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: Combine Rows with Calculation (Dupe in one column)

    I am dumb, I forgot in the sample I removed a bunch of unnecessary columns.
    I was running the code on my original with all columns up to BJ. I will try again.

    Both seemed to work now. Now I just need to see if it will work on 800k rows. I tested it on 70k and it worked. Previously all methods I tried was crashing. Even "kutools" built in feature for that could not handle it.

    Thanks!
    Last edited by NewYears1978; 05-20-2021 at 11:56 AM.

+ 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. Displaying rows of dupe orders with discrepancies..
    By Jadanar in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-16-2019, 06:12 PM
  2. VBA - Combine Duplicate Rows into One and perform calculation
    By polinew in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-29-2013, 02:30 PM
  3. [SOLVED] Color dupe rows but differentiate
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-04-2012, 01:25 PM
  4. Optimize delete dupe rows
    By Engineers2008 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-20-2010, 04:54 PM
  5. Color fill rows based on dupe value
    By jp1980 in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 04-24-2009, 01:56 PM
  6. [SOLVED] Dupe check over more than one column
    By Wynn in forum Excel General
    Replies: 3
    Last Post: 06-16-2005, 10:05 PM
  7. how do i "de-dupe?" rows by a column value?
    By hailah in forum Excel General
    Replies: 1
    Last Post: 05-20-2005, 12:06 AM

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