getting rid of multiple entries of the same name but adding a value together

Ivn68

Board Regular
Joined
Aug 21, 2015
Messages
75
in columnA I have a name and in columnB I have a value
there would be multiple entries for the same name but different values in columnB
i need to get rid of the duplicate entry but the values in columnB to be added together

thinkng im gonna need to run a loop in vba
 
It's adding it up and putting the result in column B and deleting the last name. I need the results to be in column C and retain the last name
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
At the moment its outputting 2 sets of results, the unique values from col A & the count from col C. Where do you want those to be output?
 
Upvote 0
Column A is first name column B is last name column C is a value. I need it get rid of duplicates but add column C together. I need column A and column B to stay the same.

So the data would look like this:

Steve Smith 2
Steve Smith 4
John Jones 5
John Jones 1

And then look like this:

Steve Smith 6
John Jones 6
 
Upvote 0
Do you only want to add the totals if both col A & B match?
At the moment it's only looking in col A
 
Upvote 0
Ok, try
Code:
Sub Totalunique()
   Dim v As String
   Dim Cl As Range
   
   With CreateObject("scripting.dictionary")
      .CompareMode = vbTextCompare
      For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
         v = Cl.Value & "|" & Cl.Offset(, 1).Value
         If Not .exists(v) Then
            .Add v, Cl.Offset(, 2).Value
         Else
            .Item(v) = .Item(v) + Cl.Offset(, 2).Value
         End If
      Next Cl
      Range("A1").CurrentRegion.Offset(1).ClearContents
      Range("A2").Resize(.Count).Value = Application.Transpose(.keys)
      Range("C2").Resize(.Count).Value = Application.Transpose(.items)
      Range("A2").Resize(.Count).TextToColumns Range("A2"), xlDelimited, , , False, False, False, False, True, "|"
   End With
End Sub
 
Upvote 0
they added more colums now!fml!

so now i have column A,B,C,D,E,F

add totals of column F if column A,B,C, are the same column D and E dont have to be the same




can you tell me how to change the code if they add more columns in the future?

what if i just need one column to match like in column C to match?
 
Last edited:
Upvote 0
To add extra columns to the match you do it like
Code:
v = Cl.Value & "|" & Cl.Offset(, 1).Value [COLOR=#0000ff]& "|" & Cl.Offset(, 2).Value[/COLOR]
and to change the column being totalled
Code:
If Not .exists(v) Then
            .Add v, Cl.Offset(, [COLOR=#ff0000]5[/COLOR]).Value
         Else
            .Item(v) = .Item(v) + Cl.Offset(, [COLOR=#ff0000]5[/COLOR]).Value
         End If
You'll also need to change this line
Code:
Range("C2").Resize(.Count).Value = Application.Transpose(.items)
to column D
 
Upvote 0
In my suggestion, you can use to filter unique values (at another place in similar table format 'C D') of column A by using "REMOVE DUPLICATE" and after you can apply SUMIFS formula to solve you purpose.

ABCD
a2a2=SUMIFS($B$2:$B$15,$A$2:$A$15,E2)
b4b5
c6c11
d8d14
e10e17
f12f20
g5g5
h5h5
i9i9
b1
c5
d6
e7
f8

<colgroup><col width="64" span="9" style="width:48pt"> </colgroup><tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,215,133
Messages
6,123,235
Members
449,092
Latest member
SCleaveland

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