If duplicate numbers exist then sum values in another column / same row

HarryFröhlich

Board Regular
Joined
Mar 25, 2003
Messages
116
Hi Everybody!

Although it was easy to figure out how to find duplicate values in a column and to calculate the number of times each entry has been duplicated, if at all, my need extends beyond that and this is where I now need your assistance, please.

The scenario: If a number is duplicated in a specific range of column A (e.g.), I need to sum all the values of column B (e.g.) that are on the same row as the duplicate entry and list that value in the row where the "last" (down in the column) duplicate entry is situated.

EXAMPLE

A1: 1 B1: 10
A2: 2 B2: 100
A3: 2 B3: 100
A4: 2 B4: 10
A5: 3 B5: 10
A6: 3 B6: 100
A7: 4 B7: 50

As you can see, Column A has two sets of duplicates: 2 is duplicated 3x and 3 is duplicated 2x.

I need to sum the values of column B in the rows where the 2 is duplicated in column A (answer = 100 + 100 + 10 = 210) AND the same for 3 (10 + 100 = 210) and place these values in column C.

Where in column C?

IN ADDITION to the above, I need the formula to write the totals of the duplicates in the row of each LAST unique duplicate number, that is, 210 must be placed in C4 and 110 in C6.

And that folks, is it!

Thanks for your attention — oh, and by the way, I'd like to be able to do it without VBA as I'd like a continuous update on the values in column C without having to run a macro. A function written in VBA is, obviously, just dandy.

If all else fails and only VBA will do the trick, is there some code that can simply run the macro when duplicate values are encountered as they are entered into the spreadsheet and ignore it otherwise?

Regards

Harry
 
I did this and it worked when it was one value. However, when it has more ID's, it messes up. Such as sorting a table by date or the amount if Col C. If I sort the table by lowest number in Col C. Which is 0's, the value becomes 0.

Did you apply control+shift+enter to the formula, that is, press down the control and the shift keys at the same time, while you hit the enter key? If done properly, Excel itself puts a pair of { and } around the formula in recognition.
 
Last edited:
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
This post has been very very helpful- thank you. I'm trying to modify this to match in two columns instead of 1. Is that possible? I have multiple location IDs with some duplicates, each location id has a county and sometimes the counties match and sometimes they don't. I need to count how many total visits per location id and county.


location IDcountyvisitshoping for
3194002A 17
3194002A2.819.8
3871708B 2.8
3871708C2.85.6
3081702A2.82.8
3081702P77
3081702P46123

<colgroup><col><col><col span="2"></colgroup><tbody>
</tbody>

<colgroup><col><col><col></colgroup><tbody>
</tbody>

This is what I wrote, but it's not summing by correctly:
=IF(AND(COUNTIF(A$2:A2,A2)=COUNTIF(A:A,A2),COUNTIF(B:B,B2)),SUMIFS($C:$C,A:A,A2),"")
adding B to the SUMIFS statement doesn't work either.
 
Upvote 0
I think I figured it out:
=IFS(AND(COUNTIF(A$2:A2,A2)=COUNTIF(A:A,A2),COUNTIF(B1,B2)=COUNTIF(B1,B2)),SUMIFS($C$2:$C2,$A$2:A2,A2,$B$2:B2,B2),AND(COUNTIF(A$2:A2,A2)<>COUNTIF(A:A,A2)),SUMIFS($C$2:$C2,$A$2:A2,A2))

If anyone has any tips or a cleaner version I'm all ears.

I pasted the values into the next column, sorted by visits, largest to smallest, then hit remove duplicates by location ID and county and it kept the 1st instance (the one with the largest visit value because of how I sorted).
 
Upvote 0
I actually used:
=IFS(AND(COUNTIF(A$2:A2,A2)=COUNTIF(A:A,A2),COUNTIF(B1,B2)=COUNTIF(B1,B2)),SUMIFS($C$2:$C2,$A$2:A2,A2,$B$2:B2,B2),AND(COUNTIF(A$2:A2,A2)=COUNTIF(A:A,A2),COUNTIF(B1,B2)<>COUNTIF(B1,B2)),C2,AND(COUNTIF(A$2:A2,A2)<>COUNTIF(A:A,A2)),C2)
 
Upvote 0
I actually used:
=IFS(AND(COUNTIF(A$2:A2,A2)=COUNTIF(A:A,A2),COUNTIF(B1,B2)=COUNTIF(B1,B2)),SUMIFS($C$2:$C2,$A$2:A2,A2,$B$2:B2,B2),AND(COUNTIF(A$2:A2,A2)=COUNTIF(A:A,A2),COUNTIF(B1,B2)<>COUNTIF(B1,B2)),C2,AND(COUNTIF(A$2:A2,A2)<>COUNTIF(A:A,A2)),C2)

This formula does not produce the output you posted in post #22 ...

In fact it doesn't agree with the following either...

Row\Col
E​
F​
G​
H​
I​
1​
location IDABCP
2​
3194002​
19.8​
0​
0​
0​
3​
3871708​
0​
2.8​
2.8​
0​
4​
3081702​
2.8​
0​
0​
123​

where

=SUMIFS($C$2:$C$8,$A$2:$A$8,$E2,$B$2:$B$8,F$1)

is implemented in in F2, copied across, and down.
 
Upvote 0
I have a very similar issue but it's a tad more complex.

I'd like to find duplicate entries column A lets say, and have it sum column B, and consolidate that total by deleting the other rows.

For Example:

Column A: Column B:

1111 300
1112 300
1111 700
11112 700

would like it to become

A: B:
1111 1000
1112 1000

I would need to do this for over 5000+ entries, and that's why I've been trying to find a way to complete this without going in and doing it manually or adding them all together. Thanks in advance, sorry if I bumped an old thread but this was very similar to what I needed.
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,093
Latest member
dbomb1414

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