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

Office Tab Enable Tabbed Editing and Browsing in Office, and Make Your Work Much Easier...
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
  • Reuse Anything: Add the most used or complex formulas, charts and anything else to your favorites, and quickly reuse them in the future.
  • More than 20 text features: Extract Number from Text String; Extract or Remove Part of Texts; Convert Numbers and Currencies to English Words.
  • Merge Tools: Multiple Workbooks and Sheets into One; Merge Multiple Cells/Rows/Columns Without Losing Data; Merge Duplicate Rows and Sum.
  • Split Tools: Split Data into Multiple Sheets Based on Value; One Workbook to Multiple Excel, PDF or CSV Files; One Column to Multiple Columns.
  • Paste Skipping Hidden/Filtered Rows; Count And Sum by Background Color; Send Personalized Emails to Multiple Recipients in Bulk.
  • Super Filter: Create advanced filter schemes and apply to any sheets; Sort by week, day, frequency and more; Filter by bold, formulas, comment...
  • More than 300 powerful features; Works with Office 2007-2019 and 365; Supports all languages; Easy deploying in your enterprise or organization.

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


Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial.
kte tab 201905

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!
officetab bottom
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 · 2 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.