If Column A has duplicates then add the value in column D for the duplicates

EquipmentPartsSales

New Member
Joined
Sep 17, 2018
Messages
6
I have a large inventory file I am working with. The data looks like this:
[TABLE="width: 500"]
<tbody>[TR]
[TD]NSN[/TD]
[TD]Part number[/TD]
[TD]Condition[/TD]
[TD]QTY[/TD]
[TD]DESC[/TD]
[/TR]
[TR]
[TD]1005001950897[/TD]
[TD]11662739[/TD]
[TD]NS[/TD]
[TD]7[/TD]
[TD]MOTOR[/TD]
[/TR]
[TR]
[TD]1005001950897[/TD]
[TD]11662739[/TD]
[TD]NS[/TD]
[TD]2[/TD]
[TD]MOTOR[/TD]
[/TR]
[TR]
[TD]1005002676740[/TD]
[TD]368506201[/TD]
[TD]NS[/TD]
[TD]4[/TD]
[TD]HOUSING[/TD]
[/TR]
[TR]
[TD]1005005013201[/TD]
[TD]5013201[/TD]
[TD]NS[/TD]
[TD]1[/TD]
[TD]SPRING[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Basically what I would like to do is if the number in column NSN has a duplicate then add up the values in the QTY column. For this example it would like like this:
[TABLE="width: 500"]
<tbody>[TR]
[TD]NSN[/TD]
[TD]Part number[/TD]
[TD]Condition[/TD]
[TD]QTY[/TD]
[TD]DESC[/TD]
[TD]Total Qty[/TD]
[/TR]
[TR]
[TD]1005001950897[/TD]
[TD]11662739[/TD]
[TD]NS[/TD]
[TD]7[/TD]
[TD]MOTOR[/TD]
[TD]9[/TD]
[/TR]
[TR]
[TD]1005001950897[/TD]
[TD]11662739[/TD]
[TD]NS[/TD]
[TD]2[/TD]
[TD]MOTOR[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1005002676740[/TD]
[TD]368506201[/TD]
[TD]NS[/TD]
[TD]4[/TD]
[TD]HOUSING[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1005005013201[/TD]
[TD]5013201[/TD]
[TD]NS[/TD]
[TD]1[/TD]
[TD]SPRING[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

I do not know if there is a simple formula or a VBA code that will achieve this. My inventory list has roughly 200,000 lines. Any help would be greatly appreciated.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi,

Is this what you mean:


Book1
ABCDEF
1NSNPart numberConditionQTYDESCTotal Qty
2100500195089711662739NS7MOTOR9
3100500195089711662739NS2MOTOR
41005002676740368506201NS4HOUSING
510050050132015013201NS1SPRING
Sheet268
Cell Formulas
RangeFormula
F2=IF(AND(COUNTIF(A$2:A2,A2)=1,COUNTIF(A$2:A$200000,A2)>1),SUMIF(A$2:A$200000,A2,D$2:D$200000),"")


Formula copied down.
 
Upvote 0
Code:
=countif(A:A,A2)

Replace A with whatever column NSN is and A2 with whatever the first row of data is after column header.



I found a VBA code as well that is currently running I will try this right after I did not want to drag the code down 200,000 lines. Thank you very much for your response it is greatly appreciated.
 
Upvote 0
I tried this one first or at least something very similar. It puts the total qty in line with the lowest duplicate like this:

[TABLE="class: cms_table"]
<tbody>[TR]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD]NSN[/TD]
[TD]Part number[/TD]
[TD]Condition[/TD]
[TD]QTY[/TD]
[TD]DESC[/TD]
[TD]Total Qty[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD]1005001950897[/TD]
[TD="align: right"]11662739[/TD]
[TD]NS[/TD]
[TD="align: right"]7[/TD]
[TD]MOTOR[/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD]1005001950897[/TD]
[TD="align: right"]11662739[/TD]
[TD]NS[/TD]
[TD="align: right"]2[/TD]
[TD]MOTOR[/TD]
[TD]9[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD]1005002676740[/TD]
[TD="align: right"]368506201[/TD]
[TD]NS[/TD]
[TD="align: right"]4[/TD]
[TD]HOUSING[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD]1005005013201[/TD]
[TD="align: right"]5013201[/TD]
[TD]NS[/TD]
[TD="align: right"]1[/TD]
[TD]SPRING

[/TD]
[/TR]
</tbody>[/TABLE]

The problem with that is when I use VBA to change the duplicates to blanks it only saves the first one. When I would go to delete the row I would lose the data.


Fixed the post
 
Upvote 0
I tried this one first or at least something very similar. It puts the total qty in line with the lowest duplicate like this:

[TABLE="class: cms_table"]
<tbody>[TR]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD]NSN[/TD]
[TD]Part number[/TD]
[TD]Condition[/TD]
[TD]QTY[/TD]
[TD]DESC[/TD]
[TD]Total Qty[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD]1005001950897[/TD]
[TD="align: right"]11662739[/TD]
[TD]NS[/TD]
[TD="align: right"]7[/TD]
[TD]MOTOR[/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD]1005001950897[/TD]
[TD="align: right"]11662739[/TD]
[TD]NS[/TD]
[TD="align: right"]2[/TD]
[TD]MOTOR[/TD]
[TD]9[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD]1005002676740[/TD]
[TD="align: right"]368506201[/TD]
[TD]NS[/TD]
[TD="align: right"]4[/TD]
[TD]HOUSING[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD]1005005013201[/TD]
[TD="align: right"]5013201[/TD]
[TD]NS[/TD]
[TD="align: right"]1[/TD]
[TD]SPRING

[/TD]
[/TR]
</tbody>[/TABLE]

The problem with that is when I use VBA to change the duplicates to blanks it only saves the first one. When I would go to delete the row I would lose the data.


Fixed the post

I'm not understanding this comment, and don't know if you're referring to my Post # 3.

Also, if using a formula solution, there's no need to "physically" copy the formula down 200000 rows.

Let me know if my formula is doing what you need, and I'll respond accordingly.
 
Upvote 0
I'm not understanding this comment, and don't know if you're referring to my Post # 3.

Also, if using a formula solution, there's no need to "physically" copy the formula down 200000 rows.

Let me know if my formula is doing what you need, and I'll respond accordingly.


Not trying to sound rude I truly do not know how do you get the formula all the way down without dragging it?
 
Upvote 0
No, not sounding rude at all, I just didn't know who you were talking to, and still don't know if my formula is working for you.

The other formula offered above Only does a COUNT of Column A, whereas, according to your description you want a SUM of Column D (Qty) for Duplicates in Column A, but ignore the unique NSN(s) in Column A (as my formula does).

Anyway, using my table in Post # 3 as sample, to quickly copy F2 formula All the Way to F200000:

1. Select F2, Right click, Copy
2. Hit F5, inside the "Reference" box, type F3:F200000
3. Hold down Shift, Click "OK"
4. Control V, the formula is now copied All the way down to F200000
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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