How to combine multiple rows into one based on duplicates in Excel?
Maybe, you have the following screenshot 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, see screenshots:
![]() |
![]() |
![]() |
Do you have some effective ways to solve this task?
Combine multiple duplicate rows into one with VBA code
Combine multiple duplicate rows into one Kutools for Excel
Combine multiple duplicate rows and sum/average the values with Kutools for Excel
Combine multiple duplicate rows into one with VBA code
The following VBA code can help you combine duplicate rows based on the value of column A, and the following code is only applied for two columns. So, if you have two columns data, this code will do a favor for you.
1. Hold down the ALT + F11 keys, and 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 multiple rows into one
Sub CombineRows()
'Update 20131202
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)
xvalue = arr(i, 1)
If Dic.Exists(xvalue) Then
Dic(arr(i, 1)) = Dic(arr(i, 1)) & " " & arr(i, 2)
Else
Dic(arr(i, 1)) = arr(i, 2)
End If
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, and a prompt box pops out to remind you to select a range that you need to combine. See screenshot:
4. And then click OK, the values in column B have been combined into one record and separated by spaces.
Notes:
1. This code can destroy the original data, when you use it, you’d better back up the data first.
2. This code is only applied for two columns, if you have more than two columns, this code will only combine first two columns and remove other columns data. When you use this code, you must be cautious.
Combine multiple duplicate rows into one Kutools for Excel
Now that the above code has some limitations and risks, is there a handy and safe way to finish this job? With Kutools for Excel’s Advanced Combine Rows utility, you can quickly remove multiple duplicate rows in the columns you based on and merge or do some calculations for other records into appropriate cells.
Kutools for Excel includes more than 300 handy Excel tools. Free to try with no limitation in 30 days. Get it Now.
After installing Kutools for Excel, please do as follows:
1. Select the range data that you want to combine duplicates.
2. Then click Kutools > Content Converter > Advanced Combine Rows. See screenshot:
3. In the Advanced Combine Rows dialog box, select the column name as the key columns that you want to combine values based on, and then click Key columns. See screenshot:
4. Then go on clicking the column that you need to combine their values into one record, and then click Combine operations and choose Only combine with separator, and pick one separator you need to separate the combined values from the right list. See screenshot:
5. After finishing the settings, click OK, and your data will be merged based on the key columns and separated by separators.
Note: If you needn’t to set the operations for the rest columns, just keep the default state.
Combine multiple duplicate rows and sum/average the values with Kutools for Excel
With this multifunctional Advanced Combine Rows utility, you can combine duplicates rows and do some calculations for the values as well.
1. Select the range data that you want to combine duplicates.
2. Go to the Advanced Combine Rows dialog box;
- (1.) Select a column name as key column that you want to calculate other column values based on, and then click Key columns;
- (2.) Select the column that you need to do some calculations for the values, and then click Combine operations > Combine calculate, then choose one calculation type that you need, in this case, I select Sum. See screenshot:
3. If you needn’t to set the operations for the rest columns, just keep the default state, then click OK, and the duplicate values in column A will be merged and their corresponding values in column B will be added up. See screenshots:
![]() |
![]() |
![]() |
Notes:
1. If you check My data has headers option, your headers (the first row) of the range will be ignored when you apply this utility.
2. Use formatted values: it will keep the formatting of the values after combining the duplicate cells.
3. This utility is not available for filtering data.
Click to know more about this Advanced Combine Rows function.
Related article:
Combine duplicate rows and sum the values
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, 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!








