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
 
How could I do it with Date, summing hours? Re: If duplicate numbers exist then sum values in another column / same row -

I have a similar problem and cannot find an answer anywhere else. I already checked the forum question.

I have in Column A (trips/walks), in column B (date and time for a "turn" during the trip). Trip 1 had two turns, therefore we collected two "readings" of date/time. Trip 2 has three turns, etc..

I want to estimate the amount of time spent in each trip by subtracting the first reading of date/time to the last reading. e.g. =B2-B1 for trip 1, =B5-B3 for trip 2, =B7-B6 for trip 3. I have thousands of trips and readings for each trip. Ideally, I would have a formula and copy down this formula in column C to get the hours for each trip.

A1=1 B1=5/23/2013 7:48
A2=1B2=5/23/2013 8:00
A3=2 B3=5/23/2013 8:14
A4=2B4=5/23/2013 8:22
A5=2 B5=5/23/2013 8:24
A6=3 B6=5/23/2013 11:08
A7=3B7=5/23/2013 11:16

<tbody>
</tbody>


I have tried to modify the code below (from Andrew Poulsom) but I cannot make it to work. Any suggestions welcomed?

Thanks in advance
Tony


In C1:

=IF(COUNTIF(A$1:A1,A1)=COUNTIF(A:A,A1),SUMIF(A:A,A1,B:B),"")

copied down.

Edit

For the duplicates only:

=IF(AND(COUNTIF(A$1:A1,A1)=COUNTIF(A:A,A1),COUNTIF(A:A,A1)>1),SUMIF(A:A,A1,B:B),"")
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Re: How could I do it with Date, summing hours? Re: If duplicate numbers exist then sum values in another column / same row -

In C1 coped down:

=IF(A2=A1,B2-B1,0)
 
Upvote 0
Re: How could I do it with Date, summing hours? Re: If duplicate numbers exist then sum values in another column / same row -

In C1 coped down:

=IF(A2=A1,B2-B1,0)


Hi Andrew, thanks for the prompt response. This formula works great but if I have many more readings in a trip, I could not estimate the hours for the entire trip. Or after this formula, should i use the formula you suggested previously?

I probably did not explain that sometimes I have more than two of readings listed for a single trip (sometimes i have dozens). My goal was trying to use a formula that subtract the oldest date/time from the newest date/time for a single trip, e.g., in trip 2, which has three readings, A5-A3. Or if I have 25 readings in a trip, subtract the first reading of the trip (the oldest date/time) from the last reading (newest date/time).

Please, If i am not explaining well, let me know.

Thanks
Tony
 
Upvote 0
Re: How could I do it with Date, summing hours? Re: If duplicate numbers exist then sum values in another column / same row -

Thank you Andrew, I think I got it. I used the both your formulas suggested in this Thread. The second one to get the hours (=IF(A2=A1,B2-B1,0) and the first one (=IF(COUNTIF(A$1:A1,A1)=COUNTIF(A:A,A1),SUMIF(A:A,A1,B:B),"")) to get the sum of hours spent in a trip.

I appreciate your help,

Tony Celis

Hi Andrew, thanks for the prompt response. This formula works great but if I have many more readings in a trip, I could not estimate the hours for the entire trip. Or after this formula, should i use the formula you suggested previously?

I probably did not explain that sometimes I have more than two of readings listed for a single trip (sometimes i have dozens). My goal was trying to use a formula that subtract the oldest date/time from the newest date/time for a single trip, e.g., in trip 2, which has three readings, A5-A3. Or if I have 25 readings in a trip, subtract the first reading of the trip (the oldest date/time) from the last reading (newest date/time).

Please, If i am not explaining well, let me know.

Thanks
Tony
 
Upvote 0
Not an answer to you question but don't you mean 5=2 (rows 1 and 5)?

Hell All,

I have a complex condition to be applied in my macro. I am new to macros so any guidance will be of help to me.
following is the condition:

please find below sample table:
CHECK IDRemarksmarks
math001correct1
math001wrong0
eng002wrong0
math001correct1
eng002wrong0
geo003correct1
eng002wrong0
geo003correct1
geo003correct1
geo003correct1
sci004wrong0
sci004correct1

<tbody>
</tbody>


now for every duplicate entry in column CheckID I want to check the remarks, if first entry is "correct" then marks have to be considered as 1 for that entry, if second occurrence of the CheckiD column is also "correct" then NO marks have to be considered for that entry, i.e marks should be 0 and not 1.

If all the remarks value for any particular CheckID is "wrong", then just one of them should be considered and have marks 0, the rest can be ignored.
 
Upvote 0
In C1:

=IF(COUNTIF(A$1:A1,A1)=COUNTIF(A:A,A1),SUMIF(A:A,A1,B:B),"")

copied down.

Edit

For the duplicates only:

=IF(AND(COUNTIF(A$1:A1,A1)=COUNTIF(A:A,A1),COUNTIF(A:A,A1)>1),SUMIF(A:A,A1,B:B),"")

Andrew,

This worked perfect for a similar problem I had. However, I want the summed value to show up in the row of the FIRST unique duplicate number. So if my duplicates are A3:A6, I would want the total to show in C3.
 
Upvote 0
Andrew,

This worked perfect for a similar problem I had. However, I want the summed value to show up in the row of the FIRST unique duplicate number. So if my duplicates are A3:A6, I would want the total to show in C3.

Row\Col
A​
B​
C​
1​
1​
10​
2​
2​
100​
210​
3​
2​
100​
4​
2​
10​
5​
3​
10​
110​
6​
3​
100​
7​
4​
50​

In C1 enter and copy down:
Rich (BB code):
=IF(INDEX(FREQUENCY(MATCH($A$1:$A$7,$A$1:$A$7,0),
    MATCH($A$1:$A$7,$A$1:$A$7,0)),ROWS($A$1:A1))>1,
    SUMIFS($B$1:$B$7,$A$1:$A$7,$A1),"")

SUMIFS can be replaced with SUMIF if the former is not available to you.
 
Upvote 0
Hi, I have a similar question. I have 3 Columns here.

So basically,

Col A. Col B Col C
Ef555 12/2/2016 15
Ef555 12/2/2016. 15
Ef555 12/3/2016. 4
Ef555. 12/6/2016. 1
Ef555. 12/6/2016. 1


So basically the Sum of Ef555 Col C should be 20. Anytime Col C is duplicated by Col A I want it to be ignored.

Any help is appreciated. Thanks!
 
Upvote 0
@JesterJayJoker

Row\Col
A​
B​
C​
D​
E​
F​
1​
2​
Ef555
12/2/2016​
15​
Ef555
20​
3​
Ef555
12/2/2016​
15​
4​
Ef555
12/3/2016​
4​
5​
Ef555
12/6/2016​
1​
6​
Ef555
12/6/2016​
1​

In F2 control+shift+enter, not just enter:

=SUM(IF(FREQUENCY(IF($A$2:$A$6=E2,IF(ISNUMBER(1/$B$2:$B$6),MATCH($B$2:$B$6,$B$2:$B$6,0))),ROW($B$2:$B$6)-ROW($B$2)+1),$C$2:$C$6))
 
Upvote 0
In F2 control+shift+enter, not just enter:

=SUM(IF(FREQUENCY(IF($A$2:$A$6=E2,IF(ISNUMBER(1/$B$2:$B$6),MATCH($B$2:$B$6,$B$2:$B$6,0))),ROW($B$2:$B$6)-ROW($B$2)+1),$C$2:$C$6))

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.
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,034
Members
448,940
Latest member
mdusw

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