Summing values from duplicate rows into the original then deleting duplicates

ThePangloss

New Member
Joined
Jun 19, 2015
Messages
40
I'm looking for a way to add up the values of duplicate rows underneath the original then delete the duplicate afterwards, whether this is through VBA or just formulas. I can't really think of any way other than using the IF function such as

=IF((A2=A3)*(B2=B3),"",SUM(C$<wbr style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; line-height: 16.8999996185303px; white-space: pre-wrap;">2:C2)-SUM(D$1:D1))

but this only works for rows that have only one duplicate row. Some of my data has three to five duplicate rows with values that I need to sum up in the main one. The rows I have are last name, first name, id number, then hours worked. Some people worked different jobs at different periods so they come up multiple times. I need to add up their total hours.

An example looks like this

john doe12812810
john doe12812821
john doe1281288
bob marley23828110
jane doe919197
jane doe9191910
mark john38328220

<tbody>
</tbody>

which I need to turn into

john doe12812839
bob marley23828110
jane doe9191917
mark john38328220

<tbody>
</tbody>

I'd appreciate any advice on this. Thanks in advance.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
nameidnumhours
john doe12812810
john doe12812821
john doe1281288
bob marley23828110Sum of hours
jane doe919197nameTotal
jane doe9191910bob marley10
mark john38328220jane doe17
john doe39
mark john20
Grand Total86
a very simple pivot table

<colgroup><col><col span="4"><col><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
=COUNTIF($A1:A$2,A1)=IF(G1=1,VALUE("1."&COUNTIF($G1:G$2,1)))
john doe1281281011.1
john doe128128212FALSE
john doe12812883FALSE
bob marley2382811011.2
jane doe91919711.3
jane doe91919102FALSE
mark john3832822011.4
=INDEX(A1:A7,MATCH(A12,H1:H7,0))=SUMIF($A$2:$A$8,$B12,$C$2:$C$8)
1.1john doe39
1.2bob marley10
1.3jane doe17
1.4mark john20
1.5#N/A0
1.6#N/A0

<tbody>
</tbody>
 
Last edited:
Upvote 0
I'm looking for a way to add up the values of duplicate rows underneath the original then delete the duplicate afterwards, whether this is through VBA or just formulas. I can't really think of any way other than using the IF function such as

=IF((A2=A3)*(B2=B3),"",SUM(C$<wbr style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; line-height: 16.8999996185303px; white-space: pre-wrap;">2:C2)-SUM(D$1:D1))

but this only works for rows that have only one duplicate row. Some of my data has three to five duplicate rows with values that I need to sum up in the main one. The rows I have are last name, first name, id number, then hours worked. Some people worked different jobs at different periods so they come up multiple times. I need to add up their total hours.

An example looks like this

john doe12812810
john doe12812821
john doe1281288
bob marley23828110
jane doe919197
jane doe9191910
mark john38328220

<tbody>
</tbody>

which I need to turn into

john doe12812839
bob marley23828110
jane doe9191917
mark john38328220

<tbody>
</tbody>

I'd appreciate any advice on this. Thanks in advance.


Pangloss, please check the formula i had sent. You need to define the unique name 1st. Just may sum out the value.
 
Upvote 0
Thanks a lot everyone! I went with Azumi's formula as it didn't involve pivot tables or secondary indexes (they're still extremely helpful ideas though!)
 
Upvote 0

Forum statistics

Threads
1,215,766
Messages
6,126,763
Members
449,336
Latest member
p17tootie

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