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 quickly merge rows based on one column value then do some calculations in Excel?

For example, you have a range of data and one column has duplicates, now you want to merge rows bases the column A (has duplicates) then do some calculations to another column based on the merged rows as screenshot shown:

In Excel, there is no quick method to merge rows based on one column value, but here I introduce the
tricks that can help you merge duplicate rows then sum or do other calculations on another column.


Easily Combine columns or rows without losing data in Excel

With Kutools for Excel's Combine Columns and Rows utility, you can quickly combine multuple cells based on row/column and separated by comma or space, or combine a range of cells into a single cell with specific separator.
For instance, here I do thses operations: (1.)Select Select Combine columns under To combine selected cells according to following options; (2.)Specify a separator for the combined data, here I select Space; (3.))Specify the cell you want to place your combined result; (4.)Specify how you want to deal with the combined cells.  Click for full-featured free trial in 60 days!
doc combine cells 1
 
Kutools for Excel: with more than 300 handy Excel add-ins, free to try with no limitation in 60 days.

Excel Productivity Tools

Office Tab: Bring powerful tabs to Office (include Excel), just like Chrome, Safari, Firefox and Internet Explorer. Save you half the time, and reduce thousands of mouse clicks for you. 30-day Unlimited Free Trial

Kutools for Excel: Save 70% of your time and solve 80% Excel problems for you. 300+ advanced features designed for 1500+ work scenario, make Excel much easy and increase productivity immediately.60-day Unlimited Free Trial


arrow blue right bubble   Merge rows based on one column then sum values with VBA

There is a VBA code can help you to merge the duplicate rows then sum another column values.

Tabbed browsing & editing multiple Excel workbooks/Word documents as Firefox, Chrome, Internet Explore 10!

You may be familiar to view multiple webpages in Firefox/Chrome/IE, and switch between them by clicking corresponding tabs easily. Here, Office Tab supports similar processing, which allow you to browse multiple Excel workbooks or Word documents in one Excel window or Word window, and easily switch between them by clicking their tabs. Click for free 45-day trial of Office Tab!

ot excel

1. Press F11 + Alt keys to enable Microsoft Visual Basic for Applications window, then click Insert > Module and copy and paste below VBA code to the new Module window.

VBA: Merge rows based on one column value

Sub MG30Nov12()
'Updateby20150519
Dim Rng As Range
Dim InputRng As Range
Dim nRng As Range
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Range :", xTitleId, InputRng.Address, Type:=8)
Set InputRng = InputRng.Parent.Range(InputRng.Columns(1).Address)
With CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
For Each Rng In InputRng
    If Not .Exists(Rng.Value) Then
        .Add Rng.Value, Rng.Offset(, 1)
    Else
        .Item(Rng.Value).Value = .Item(Rng.Value).Value + Rng.Offset(, 1)
            If nRng Is Nothing Then
                Set nRng = Rng
            Else
                Set nRng = Union(nRng, Rng)
            End If
    End If
Next
If Not nRng Is Nothing Then
    nRng.EntireRow.Delete
End If
End With
End Sub

2. Press F5 or click Run button to run the VBA, and a dialog pops out for selecting a data range to work. see screenshot:

doc merge columns based on one column 3

3. After selecting a working range, click OK. Now the data has been merged by first column and sum the values in second column.

doc merge columns based on one column 4

Note: This VBA code just can correctly work when merging based on the first column and sum values in the second column.


arrow blue right bubble   Merge rows based on one column then sum values with Advanced Combine Rows

If you are not familiar with VBA code, you can use the Advanced Combine Rows feature of the third part add-in tool – Kutools for Excel to easily and quickly merge the duplicates rows then sum the values in another column.

  Kutools for Excel, with more than 300 handy functions, makes your jobs more easier. 

After free installing Kutools for Excel, please do as below:

1. Select the data you want to use and click Kutools > Content > Advanced Combine Rows. See screenshot:

doc advanced combine row 1

2. Then in the popping dialog, select the column which you will merge other columns based on then click Primary Key, and click another column and click Calculate then select Sum.

Tip: If your selected range has headers, check My data has headers, and check Use formatted values will keep the formatting after merging.

doc merge columns based on one column 6

3. Then click Ok. Now the data has been merge based on the primary column, and another is sum up. See screenshot:

doc merge columns based on one column 7


arrow blue right bubble   Merge rows based on one column then do different operations on other columns with Advanced Combine Rows.

Advanced Combine Rows is powerful, because it not only can merge duplicate rows in one column then sum another column, but also can merge duplicate rows in one column then do different operations on other columns.

Suppose I have a range of data as below screenshot shown, and I want to both combine values in Column B and sum values in Column C based on Column A.
doc merge columns based on one column 8

After free installing Kutools for Excel, please do as below:

1. Select data range and click Kutools > Contents > Advanced Combine Rows. See screenshot:

doc advanced combine row 1

2. In the Combine Rows Based on Column dialog, do like these:

(1) Click at the column you want to combine based on, and click Primary Key;

doc merge columns based on one column 10

(2) Click at the column you want to combine data, and click Combine, then select one separator you need from the list;

doc merge columns based on one column 11

(3) Click at the column you want to sum values and click Calculate, and select Sum.

doc merge columns based on one column 12

3. Click Ok. Now you can see the result as below:

doc merge columns based on one column 13

With Advanced Combine Rows feature, you also can merge rows based on one column then count, average, keep 1st or last data in other columns.

pay attention1If you are interested in this addi-in, click here to download the 60-days free trial.

doc KTE

 


Excel Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 70%, 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 80% 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.

Be the first to comment.