Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to combine duplicate rows and sum the values in Excel?

doc-combine-sum1 -2 doc-combine-sum2

In Excel,you may always meet this problem, when you have a range of data which contains some duplicate entries, and now you want to combine the duplicate data and sum the corresponding values in another column, as following screenshots shown. How could you solve this problem?

Combine duplicate rows and sum the values with Consolidate function

Combine duplicate rows and sum the values with VBA code

Combine duplicate rows and sum the values with Kutools for Excel

Combine corresponding rows based on duplicate values in another column with Kutools for Excel


Advanced Combine Rows:(Combine duplicate rows and sum / average corresponding values):

  • 1. Specify the key column that you want to combine other column based on;
  • 2. Choose one calculation for your combined data.
  • doc multiply then sum 07

    Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no limitation in 60 days. Download and free trial Now!


    arrow blue right bubble Combine duplicate rows and sum the values with Consolidate function


    The Consolidate is a useful tool for us to consolidate multiple worksheets or rows in Excel, so with this function, we can also summarize multiple rows based on the duplicates. Please do with the following steps:

    1. Click a cell where you want to locate the result in your current worksheet.

    2. Go to click Data > Consolidate, see screenshot:

    doc-combine-sum3

    3. In the Consolidate dialog box:

    • (1.) Select Sum from Function drop down list;
    • (2.) Click doc-combine-sum5 button to select the range that you want to consolidate, and then click Add button to add the reference to All references list box;
    • (3.) Check Top row and Left column from Use labels in option. See screenshot:

    doc-combine-sum4

    4. After finishing the settings, click OK, and the duplicates are combined and summed. See screenshot:

    doc-combine-sum6

    Note: If the range do not have the header row, you need uncheck Top row from the Use labels in option.


    arrow blue right bubble Combine duplicate rows and sum the values with VBA code

    The following VBA code also can help you consolidate duplicate rows in the worksheet, but at the same time, the original data will be destroyed, you need to backup a copy of the data.

    1. Hold down the ALT + F11 keys, then it opens the Microsoft Visual Basic for Applications window.

    2. Click Insert > Module, and paste the following code in the Module Window.

    VBA code: Combine duplicate rows and sum the values

    Sub CombineRows()
    'Update 20130829
    Dim WorkRng As Range
    Dim Dic As Variant
    Dim arr As Variant
    On Error Resume Next
    xTitleId = "KutoolsforExcel"
    Set WorkRng = Application.Selection
    Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
    Set Dic = CreateObject("Scripting.Dictionary")
    arr = WorkRng.Value
    For i = 1 To UBound(arr, 1)
        Dic(arr(i, 1)) = Dic(arr(i, 1)) + arr(i, 2)
    Next
    Application.ScreenUpdating = False
    WorkRng.ClearContents
    WorkRng.Range("A1").Resize(Dic.Count, 1) = Application.WorksheetFunction.Transpose(Dic.keys)
    WorkRng.Range("B1").Resize(Dic.Count, 1) = Application.WorksheetFunction.Transpose(Dic.items)
    Application.ScreenUpdating = True
    End Sub
    

    3. Then press F5 key to run this code, and you need to select the range that you want to consolidate in the popped out prompt box. See screenshot:

    doc-combine-sum7

    4. And then click OK, the duplicate rows have been combined and the values are added up.

    Note: If you want to use this code, you’d better make a copy of the file to avoid destroying the data, and this code is only applied to two columns.


    arrow blue right bubble Combine duplicate rows and sum the values with Kutools for Excel

    Here, I introduce the handy tool -- Kutools for Excel for you, its Advanced Combine Rows also can quickly do a favor to solve this problem.

    Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 60 days. Get it Now .

    After installing Kutools for Excel, please do as follows:

    1. Select the range you need and click Kutools > Content > Advanced Combine Rows. See screenshot:

    doc-combine-sum7

    2. In the Advanced Combine Rows dialog, check My data has headers if your range have headers, and select column name which you want to combine the duplicates and click Primary Key, see screenshot:

    doc-combine-sum7

    3. And then select the column name you want to sum the values and click Calculate > Sum or other calculations as you need. See screenshot:

    doc-combine-sum7

    4. Click Ok to close dialog, then you can see the duplicates are combined and the corresponding data in another column are added up together. See screenshots:

    doc-combine-sum1 -2 doc-combine-sum2

    Click here to know more on Advanced Combine Rows.


    arrow blue right bubble Combine corresponding rows based on duplicate values in another column with Kutools for Excel

    Sometimes, you want to combine the rows based on duplicate values in another column, the Advanced Combine Rows of Kutools for Excel also can do a favor for you, please do as follows:

    1. Select the data range that you want to use, and then click Kutools > Content > Advanced Combine Rows to enable the Advanced Combine Rows dialog box.

    2. In the Advanced Combine Rows dialog box, click the column name that you want to combine other data based on, and click Primary Key, see screenshot:

    doc-combine-sum7

    3. And then click another column name that you want to combine the data, and click Combine to choose a separator to separate your combined values, see screenshot:

    doc-combine-sum7

    4. Then click Ok, all the values with the same cell in column A have been combined together, see screenshots:

    doc-combine-sum1 -2 doc-combine-sum2

    arrow blue right bubble Combine duplicate rows and sum the values with Kutools for Excel

    Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no limitation in 60 days. Download and free trial Now!


    Related article:

    Combine multiple rows into one based on duplicate values



    Recommended Productivity Tools for Excel

    Kutools for Excel Helps You Always Finish Work Ahead of Time, and Stand Out From Crowd

    • More than 300 powerful advanced features, designed for 1500 work scenarios, increasing productivity by 70%, give you more time to take care of family and enjoy life.
    • No longer need memorizing formulas and VBA codes, give your brain a rest from now on.
    • Become an Excel expert in 3 minutes, Complicated and repeated operations can be done in seconds, 
    • Reduce thousands of keyboard & mouse operations every day, say goodbye to occupational diseases now.
    • 110,000 highly effective people and 300+ world-renowned companies' choice.
    • 60-day full features free trial. 60-day money back guarantees. 2 years of free upgrade and support.

    Brings Tabbed Browsing and Editing to Microsoft Office, Far More Powerful Than The Browser's Tabs

    • Office Tab is designed for Word, Excel, PowerPoint and Other Office Applications: Publisher, Access, Visio and Project.
    • Open and create multiple documents in new tabs of the same window, rather than in new windows.
    • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
    Say something here...
    symbols left.
    You are guest ( Sign Up? )
    or post as a guest, but your post won't be published automatically.
    Loading comment... The comment will be refreshed after 00:00.
    • To post as a guest, your comment is unpublished.
      Alex Lesyk · 2 months ago
      An absolute mess of an explantation. Thanks for the effort but it did nothing to help.
    • To post as a guest, your comment is unpublished.
      andreaB · 5 months ago
      LOVE IT!!! YOUR SAVE MY LIFE!!
    • To post as a guest, your comment is unpublished.
      sarah · 8 months ago
      Ifsum=(columns include,start point row,sum column)
      Example ifsum=(A:D,B:2,D:D)
      WAY EASIER!
    • To post as a guest, your comment is unpublished.
      chinna raju · 1 years ago
      Hi Am chinnaraju

      can u please assist for this. Any one?

      =VLOOKUP(M5,E:F,2,)


      Thanks in advance.
    • To post as a guest, your comment is unpublished.
      chinna raju · 1 years ago
      Hi,
      Can you please explain or share the Formula for below
      A5 A6 A7
      i want answer for KTO as Transpose Rice Biryani Prawns

      Left coloumn Right Coloumn
      KTO Rice
      Office Tab Curd Rice
      KTO Biryani
      Ranjith Chiken
      KTO Prawns

      Thanks,
      Chinnaraju
      9849212552