Find Duplicate Rows across multiple columns, sum dupes to a column, remove duplicates. VBA?

jrsmoots

New Member
Joined
Aug 8, 2019
Messages
2
I have a spreadsheet like this:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]UN[/TD]
[TD]Job[/TD]
[TD]RG[/TD]
[TD]AS[/TD]
[TD]TH[/TD]
[TD]SumDupes[/TD]
[/TR]
[TR]
[TD]L217028[/TD]
[TD]1[/TD]
[TD]B[/TD]
[TD]12[/TD]
[TD]75[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]L217028[/TD]
[TD]1[/TD]
[TD]C[/TD]
[TD]12[/TD]
[TD]50[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]L217028[/TD]
[TD]1[/TD]
[TD]C[/TD]
[TD]12[/TD]
[TD]50[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]L217028[/TD]
[TD]1[/TD]
[TD]C[/TD]
[TD]12[/TD]
[TD]100[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]L217028[/TD]
[TD]2[/TD]
[TD]A[/TD]
[TD]6[/TD]
[TD]50[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

I need to find duplicates: duplicate in this case means that the "Job", "RG" and "AS" are identical. So in above sample the 2nd, 3rd and 4th data rows would be considered duplicates.

I need to then sum the "TH" column for these duplicates. So, 50+50+50.

I then need to remove the duplicates (consolidate?) it down to one row, that row having the total from the duplicates (the 50+50+50).

I'm pretty comfortable with VBA, less comfortable with Excel formulas. Is this procedure something I could do from within Excel, using VBA? Trying to figure out how to present this functionality to the end user too...Maybe they could run a Macro that calls a VBA function?

I try concatenating the three columns that might might be duplicates, and tried the following formulas, which work for finding duplicates

IF(COUNTIF($H$2:H2,H2)>1, " Here I am! I'm a duplicate!","Original")

And summing duplicates:
=IF(AND(COUNTIF(H$2:H2,H2)=COUNTIF(H:H,H2),COUNTIF(H:H,H2)>1),SUMIF(H:H,H2,F:F),"")

from: https://www.mrexcel.com/forum/excel...-then-sum-values-another-column-same-row.html

Thanks in advance!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hi & welcome to MrExcel.
How about
Code:
Sub jrsmoots()
   Dim Cl As Range, Rng As Range
   Dim Vlu As String
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("B2", Range("B" & Rows.Count).End(xlUp))
         Vlu = Cl.Value & "|" & Cl.Offset(, 1).Value & "|" & Cl.Offset(, 2).Value
         If Not .exists(Vlu) Then
            .Add Vlu, Cl.Offset(, 3)
         Else
            .Item(Vlu).Value = .Item(Vlu) + Cl.Offset(, 3).Value
            If Rng Is Nothing Then Set Rng = Cl Else Set Rng = Union(Rng, Cl)
         End If
      Next Cl
   End With
   If Not Rng Is Nothing Then Rng.EntireRow.Delete
End Sub
 
Upvote 0
Hello,

I need to do the same but instead I have to add and sum one more cell and the end of the row.

Can you please help me??

1633016327109.png
 
Upvote 0
Hi & welcome to MrExcel.
Please start a new thread for your question. You are far more likely to get a response.
 
Upvote 0

Forum statistics

Threads
1,223,948
Messages
6,175,579
Members
452,653
Latest member
craigje92

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top