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 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:

doc-advanced-combine1 -2 doc-advanced-combine2

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


arrow blue right bubbleCombine 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:

doc-advanced-combine3

4. And then click OK, the values in column B have been combined into one record and separated by spaces.

doc-advanced-combine4

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.


arrow blue right bubbleCombine 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.

doc-advanced-combine5

2. Then click Kutools > Content Converter > Advanced Combine Rows. See screenshot:

doc-advanced-combine6

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:

doc-advanced-combine7

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:

doc-advanced-combine8

5. After finishing the settings, click OK, and your data will be merged based on the key columns and separated by separators.

doc-advanced-combine9

Note: If you needn’t to set the operations for the rest columns, just keep the default state.


arrow blue right bubbleCombine 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:

doc-advanced-combine10

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:

doc-advanced-combine11 -2 doc-advanced-combine12

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


Recommended Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 71%, and Help You To Stand Out From Crowd!

Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for 1500+ work scenarios, helps you solve 82% Excel problems.

  •  Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
  •  Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  •  Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
  •  Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
  •  No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
  •  Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
  •  60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  •  Change the way you work now, and give you a better life immediately!

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!
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.
    Ashley · 1 years ago
    I have used the code above successfully in the past however today, it is deleting column B. Looks like it's just removing duplicates...not sure what the issue is.

    Sample Data
    Reece, Ashley G01-Registered-UWG
    Reece, Chris G02-Registered-KSU
    Reece, Chris G03-Dropped-KSU
    Reece, Jayden G02-Registered-UNG
    Reece, Jayden G02-Withdrawn-UNG
  • To post as a guest, your comment is unpublished.
    Muveen · 1 years ago
    I have in column A

    1 Cast
    2 Crew
    3 Hiring
    4 Cast
    5 Hiring
    6 Crew

    I need these unique CAST CREW AND HIRING in another column without delete in column A entries.

    Ex: I need (after formula)

    1 Cast
    2 Crew
    3 Hiring

    Is it possible by formula?
  • To post as a guest, your comment is unpublished.
    Ilaiyaraja · 3 years ago
    Above Macro only Combine the limited cell(e.g 20 cells) in b column. How to Combine more cells
  • To post as a guest, your comment is unpublished.
    David Greene · 5 years ago
    I've found that the "Combine multiple duplicate rows and sum/average the values" feature within KUTools does not work if the numbers in the row have a comma or period. This makes the tool unusable for combining and summing currency fields (which is why I tried the product in first place). I'm currently using the trial version which states that it is full-functioned; is it possible that this works in the paid version?
    • To post as a guest, your comment is unpublished.
      Admin-jay · 5 years ago
      [quote name="David Greene"]I've found that the "Combine multiple duplicate rows and sum/average the values" feature within KUTools does not work if the numbers in the row have a comma or period. This makes the tool unusable for combining and summing currency fields (which is why I tried the product in first place). I'm currently using the trial version which states that it is full-functioned; is it possible that this works in the paid version?[/quote]
      Sorry, we will fix it in next version.