Skip to main content

Combine duplicate rows and sum their values in Excel (Simple Tricks)

Author: Xiaoyang Last Modified: 2025-04-14

In Excel, it's a common scenario to encounter a dataset with duplicate entries. Often, you might find yourself with a range of data where the key challenge is to efficiently combine these duplicate rows while simultaneously summing up the values in a corresponding column as following screenshot shown. In this context, we'll delve into several practical methods that can help you consolidate duplicate data and aggregate their associated values, enhancing both the clarity and utility of your Excel workbooks.


Combine duplicate rows and sum the values with the Consolidate function

The Consolidate is a useful tool for us to consolidate multiple worksheets or rows in Excel, with this feature, we can combine duplicate rows and sum up their corresponding values quickly and easily. Please do with the following steps:

Step 1: Select a Destination Cell

Choose where you want the consolidated data to appear.

Step 2: Access the Consolidate Function and set up the consolidation

  1. Click "Data" > "Consolidate", see screenshot:
    A screenshot of the Consolidate option in Excel ribbon
  2. In the "Consolidate" dialog box:
    • (1.) Select "Sum" from "Function" drop down list;
    • (2.) Click to select the range that you want to consolidate in the "Reference" box;
    • (3.) Check "Top row" and "Left column" from "Use labels in" option;
    • (4.) Finally, click "OK" button.
    • A screenshot of the options in the Consolidate dialog box, including Function, Reference, and Use labels in settings

Result:

Excel will combine any duplicates found in the first column and sum their corresponding values in the adjacent columns as following screenshot shown:

A screenshot of Excel after consolidation, showing combined duplicate rows and summed values

Notes:
  • If the range doesn't include a header row, ensure to "uncheck Top row" from the "Use labels in" option.
  • With this feature, calculations can only be consolidated based on the first column (the leftmost one) of the data.

Use Kutools to combine duplicate rows and sum the values

If you have installed "Kutools for Excel", its "Advanced Combine Rows" feature allows you to easily combine duplicate rows, providing options to sum, count, average, or execute other calculations on your data. Moreover, this feature isn't limited to just one key column, it can handle multiple key columns, making complex data consolidation tasks much easier.

Kutools for Excel offers over 300 advanced features to streamline complex tasks, boosting creativity and efficiency. Itegarate with AI capabilities, Kutools automates tasks with precision, making data management effortless. Detailed information of Kutools for Excel...         Free trial...

After installing "Kutools for Excel", select the data range, and then click "Kutools" > "Merge & Split" > "Advanced Combine Rows".

In the "Advanced Combine Rows" dialog box, please set the following operations:

  1. Click the column name that you want to combine duplicates based on, here, I will click Product, and then select "Primary Key" from the drop-down list in the "Operation" column;
  2. Then, select the column name you want to sum the values, and then select "Sum" from the drop-down list in the "Operation" column;
  3. As for the other columns, you can choose the operation you need, such as combining the values with a specific separator or performing a certain calculation; (this step can be ignored if you have only two columns)
  4. At last, you can preview the combined result then click "OK" button.
  5. A screenshot of Kutools' Advanced Combine Rows dialog box, with options to combine duplicates and sum values

Result:

Now, the duplicate values in the key column are combined, and other corresponding values are summed up as following screenshot shown:

A screenshot showing the result of combining duplicate rows and summing values in Excel using Kutools

Tips:
  • With this useful feature, you can also combine rows based on duplicate cell value as following demo shown:
    An animated demonstration of combining rows based on duplicate values in Excel using Kutools
  • This feature "supports Undo", if you want to recover your original data, just press "Ctrl + Z".
  • To apply this feature, please download and install Kutools for Excel.

Use Pivot Table to combine duplicate rows and sum the values

Pivot Tables in Excel provide a dynamic way to rearrange, group, and summarize data. This functionality becomes incredibly useful when you are faced with a dataset filled with duplicate entries and need to sum corresponding values.

Step 1: Creating a Pivot Table

  1. Select the data range. And then, go to the "Insert" tab, and click "Pivot Table", see screenshot:
    A screenshot of selecting the Pivot Table option from the Insert tab in Excel
  2. In the popped-out dialog box, choose where you want the Pivot Table report to be placed, you can put it to a new sheet or existing sheet as you need. Then, click "OK". See screenshot:
    A screenshot of the Pivot Table dialog box, where you can choose to insert the table in a new or existing sheet
  3. Now, a Pivot Table is inserted in the selected destination cell. See screenshot:
    A screenshot showing a blank Pivot Table inserted in the Excel worksheet

Step 2: Configuring the Pivot Table: 

  1. In the "PivotTable Fields" pane, drag the field containing duplicates to the "Row" area. This will group your duplicates.
  2. Next, drag the fields with the values you want to sum to the "Values" area. By default, Excel sums the values. See the demo below:
  3. An animated demonstration of configuring the Pivot Table fields to group duplicates and sum values in Excel

Result:

The Pivot Table now displays your data with duplicates combined and their values summed up, offering a clear and concise view for analysis. See screenshot:

A screenshot showing the result of combining duplicate rows and summing values using a Pivot Table in Excel


Use VBA code to combine duplicate rows and sum the values

If you are interested in VBA code, in this section, we will give a VBA code to consolidate duplicate rows and sum the corresponding values in other columns. Please do with the following steps:

Step 1: Open the VBA sheet module editor and copy the code

  1. Hold down the "ALT + F11" keys in Excel to open 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 CombineDuplicateRowsAndSumForMultipleColumns()
    'Update by Extendoffice
        Dim SourceRange As Range, OutputRange As Range
        Dim Dict As Object
        Dim DataArray As Variant
        Dim i As Long, j As Long
        Dim Key As Variant
        Dim ColCount As Long
        Dim SumArray() As Variant
        Dim xArr As Variant
        Set SourceRange = Application.InputBox("Select the original range:", "Kutools for Excel", Type:=8)
        If SourceRange Is Nothing Then Exit Sub
        ColCount = SourceRange.Columns.Count
        Set OutputRange = Application.InputBox("Select a cell for output:", "Kutools for Excel", Type:=8)
        If OutputRange Is Nothing Then Exit Sub
        Set Dict = CreateObject("Scripting.Dictionary")
        DataArray = SourceRange.Value
        For i = 1 To UBound(DataArray, 1)
            Key = DataArray(i, 1)
            If Not Dict.Exists(Key) Then
                ReDim SumArray(1 To ColCount - 1)
                For j = 2 To ColCount
                    SumArray(j - 1) = DataArray(i, j)
                Next j
                Dict.Add Key, SumArray
            Else
                xArr = Dict(Key)
                For j = 2 To ColCount
                    xArr(j - 1) = xArr(j - 1) + DataArray(i, j)
                Next j
                Dict(Key) = xArr
            End If
        Next i
        OutputRange.Resize(Dict.Count, ColCount).ClearContents
        i = 1
        For Each Key In Dict.Keys
            OutputRange.Cells(i, 1).Value = Key
            For j = 1 To ColCount - 1
                OutputRange.Cells(i, j + 1).Value = Dict(Key)(j)
            Next j
            i = i + 1
        Next Key
        Set Dict = Nothing
        Set SourceRange = Nothing
        Set OutputRange = Nothing
    End Sub
    

Step 2: Execute the code

  1. After pasting this code, please press "F5" key to run this code. In the prompt box, select the data range that you want to combine and sum. And then, click "OK".
    A screenshot of selecting the data range in the VBA input box to combine and sum duplicate rows
  2. And in the next prompt box, select a cell where you will output the result, and click "OK".
    A screenshot of selecting the output cell in the VBA input box for combined and summed results

Result:

Now, the duplicate rows are merged, and their corresponding values have been summed up. See screenshot:

A screenshot of the results after running the VBA code to combine duplicate rows and sum their values


Combining and summing duplicate rows in Excel can be simple and efficient. Choose from the easy Consolidate function, the advanced Kutools, the analytical Pivot Tables, or the flexible VBA coding to find a solution that suits your skills and needs. If you're interested in exploring more Excel tips and tricks, our website offers thousands of tutorials, please click here to access them. Thank you for reading, and we look forward to providing you with more helpful information in the future!


Related Articles:

  • Combine multiple rows into one based on duplicates
  • Maybe, you have a range of data, in the Product name column A, there are some duplicate items, and now you need to remove the duplicate entries in column A but combine the corresponding values in column B.How could aove this task in Excel?
  • Vlookup and return multiple values without duplicates
  • Sometimes, you may want to vlookup and return multiple matched values into a single cell at once. But, if there are some repeated values populated into the returned cells, how could you ignore the duplicates and only keep the unique values when returning all matching values as following screenshot shown in Excel?
  • Combine rows with same ID/name
  • For example, you have a table as below screenshot shown, and you need to combine rows with the order IDs, any ideas? Here, this article will introduce two solutions for you.