Count like items and remove duplicates from list

artz

Well-known Member
Joined
Aug 11, 2002
Messages
830
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have a large bill of materials for a printed circuit board in an Excel spreadsheet. Using the sort function, I was able to sort the columns based on part value; that got me part way of what I need.

What I still need however, is a macro or cell formula to do two things:

1) For a given value, provide count of like values and place count in column N
2) Remove the duplicate rows with the same values

The rows with duplicates should only removes rows in columns K, L, M, and N. (there are other active columns on the worksheet)

Below is a partial screenshot of the worksheet. The used range not including header rows is K6 - M6. This also doesn't include the count column range in column N.

Excel Workbook
KLMN
5ValueDigikey PNDescriptionCount
610P10.0HCT-NDRES 10.0 OHM 1/10W 1% 0603 SMD*
7511P511HCT-NDRES 511 OHM 1/10W 1% 0603 SMD*
8511P511HCT-NDRES 511 OHM 1/10W 1% 0603 SMD*
90.01uFPCC1750CT-NDCAP 10000PF 16V CERM X7R 0603*
100.01uFPCC1750CT-NDCAP 10000PF 16V CERM X7R 0603*
110.01uFPCC1750CT-NDCAP 10000PF 16V CERM X7R 0603*
120.01uFPCC1750CT-NDCAP 10000PF 16V CERM X7R 0603*
130.01uFPCC1750CT-NDCAP 10000PF 16V CERM X7R 0603*
140.01uFPCC1750CT-NDCAP 10000PF 16V CERM X7R 0603*
150.05 1WWSCB-50CT-NDRES 50 OHM 1W 1% 2515 WW SMD*
160.1F445-1317-1-NDCAP CER .10UF 16V X7R 10% 0603*
170.1F445-1317-1-NDCAP CER .10UF 16V X7R 10% 0603*
180.1F445-1317-1-NDCAP CER .10UF 16V X7R 10% 0603*
190.1F445-1317-1-NDCAP CER .10UF 16V X7R 10% 0603*
200.1F445-1317-1-NDCAP CER .10UF 16V X7R 10% 0603*
210.22uF445-1318-1-NDCAP CER .22UF 16V X7R 10% 0603*
221.5MegP1.50MHCT-NDRESISTOR 1.50M OHM 1/10W 1% 0603*
231.5MegP1.50MHCT-NDRESISTOR 1.50M OHM 1/10W 1% 0603*
241.5MegP1.50MHCT-NDRESISTOR 1.50M OHM 1/10W 1% 0603*
251000pF490-1494-1-NDCAP CER 1000PF 50V 10% X7R 0603*
261000pF490-1494-1-NDCAP CER 1000PF 50V 10% X7R 0603*
271000pF490-1494-1-NDCAP CER 1000PF 50V 10% X7R 0603*
28100KP100KHCT-NDRES 100K OHM 1/10W 1% 0603 SMD*
29100KP100KHCT-NDRES 100K OHM 1/10W 1% 0603 SMD*
30100KP100KHCT-NDRES 100K OHM 1/10W 1% 0603 SMD*
31100KP100KHCT-NDRES 100K OHM 1/10W 1% 0603 SMD*
32100KP100KHCT-NDRES 100K OHM 1/10W 1% 0603 SMD*
33100KP100KHCT-NDRES 100K OHM 1/10W 1% 0603 SMD*
34100KP100KHCT-NDRES 100K OHM 1/10W 1% 0603 SMD*
35100KP100KHCT-NDRES 100K OHM 1/10W 1% 0603 SMD*
36100K3214W-104ECT-NDTRIMPOT 100K OHM 4MM TOP ADJ SMD*
37100KP100KHCT-NDRES 100K OHM 1/10W 1% 0603 SMD*
38100KP100KHCT-NDRES 100K OHM 1/10W 1% 0603 SMD*
39100KP100KHCT-NDRES 100K OHM 1/10W 1% 0603 SMD*
40100KP100KHCT-NDRES 100K OHM 1/10W 1% 0603 SMD*
41100KP100KHCT-NDRES 100K OHM 1/10W 1% 0603 SMD*
PCB_BOM




Is anyone in the Forum able to offer some code to do this? Any help is greatly appreciated.

Thanks,

Art
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
If you have Excel 2007 or greater, then this is a builtin feature -- Data tab, Remove duplicates.
 
Upvote 0
Hi artz,

You say to count based on value and remove duplicates.

In your example, rows 28 to 41 have the same values, but there are 2 different descriptions in this group:

P100KHCT-ND
3214W-104ECT-ND

In this example, the count based on value would be 14, but is row 36 a duplicate ?

ColinKJ
 
Upvote 0
Hi artz,

Here's a macro that counts the values column, and deletes duplicates based on the value row:

Code:
Sub CountRemove()
R = Range("K" & Rows.Count).End(xlUp).Row
For a = R To 6 Step -1
ct = 1
x = Cells(a, 11)
y:
If Cells(a - 1, 11) = x Then
ct = ct + 1
Range("K" & a & ":N" & a).ClearContents
a = a - 1
GoTo y
Else
Cells(a, 14) = ct
End If
Next a
Range("K6:N" & R).Select
    Selection.Sort Key1:=Range("K6"), Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
Cells(6, 11).Select
End Sub

I've put together an example WB called CountDelete, which you can download from :

http://www.box.net/shared/jqd3vd4cd0

Ctrl+q to activate

ColinKJ
 
Upvote 0
Hi ColinKJ,

Thanks for your response. You are right, I think that we need to count by Digikey PN. That should provide unambiguous identifiers. Do you have a suggestion on how to do what I need using column L?

Thanks,

Art
 
Upvote 0
BobUmlas,

Thanks for the tip. I didn't know feature was available. Unfortunately, unless it also counts the number of dupes it deletes, it does help in this case.

Regards,

Art
 
Upvote 0
Hi artz,

I've updated it based on column L:

Code:
Sub CountRemove()
R = Range("K" & Rows.Count).End(xlUp).Row
Range("K6:N" & R).Select
    Selection.Sort Key1:=Range("L6"), Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
For a = R To 6 Step -1
ct = 1
x = Cells(a, 12)
y:
If Cells(a - 1, 12) = x Then
ct = ct + 1
Range("K" & a & ":N" & a).ClearContents
a = a - 1
GoTo y
Else
Cells(a, 14) = ct
End If
Next a
Range("K6:N" & R).Select
    Selection.Sort Key1:=Range("L6"), Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
Cells(6, 11).Select
End Sub

I've also updated the example WB CountDelete:

http://www.box.net/shared/jqd3vd4cd0

Ctrl+q to activate

Regards

Colin
 
Upvote 0
Colin,

You are awesome! Thanks, it worked great. The only thing though that I should have thought of was that by overwriting the range, I lost my original list. And unfortunately, I didn't save a worksheet with the original table in columns K,L, and M. I can create another one though.

Is there a way to modify what you wrote so that columns K,L, and M stay intact, and the counted and deleted dupes data, i.e., what is written to columns K, L, M and N with your sub is shifted over to say start at column P and would include columns P, Q, R, and S? Make sense?

This is a tool that will use often so it would be really great if you could make this mod if this isn't too complicated.

Thanks,

Art
 
Upvote 0
Hi artz,

Try this one:

Code:
Sub CountMove()
R = Range("K" & Rows.Count).End(xlUp).Row
Range("K6:N" & R).Select
    Selection.Sort Key1:=Range("L6"), Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
For a = R To 6 Step -1
ct = 1
x = Cells(a, 12)
y:
If Cells(a - 1, 12) = x Then
ct = ct + 1
Range("K" & a & ":N" & a).Cut
Cells(a, 16).Select
ActiveSheet.Paste
a = a - 1
GoTo y
Else
Cells(a, 14) = ct
End If
Next a
Cells(6, 11).Select
End Sub

You can download an exmple WB named CountMove from:

http://www.box.net/shared/yvllbpimli

Again, Ctrl+q to activate.

Regards

Colin
 
Upvote 0
Hi Colin,

Thanks for taking a stab at a reformulation. When I run the sub, parts with a quantity of 1 were dropped from the reconstituted (original) list and quantities greater than 1 show a quantity 1 less than the number in column the reconstituted (original) list.

Also, there are a lot of empty rows in both tables. Any chance that you can take a look. Below is an excerpt from the output:

Excel Workbook
KLMNOPQR
5ValueDigikey PNDescription*****
6XC2C32A-6VQG44C122-1410-NDIC CR-II CPLD 64MCELL 44-VQFP1****
71N41481N4148W-FDICT-NDDIODE SWITCH 100V 400MW SOD1236****
8*****1N41481N4148W-FDICT-NDDIODE SWITCH 100V 400MW SOD123
9*****1N41481N4148W-FDICT-NDDIODE SWITCH 100V 400MW SOD123
10*****1N41481N4148W-FDICT-NDDIODE SWITCH 100V 400MW SOD123
11*****1N41481N4148W-FDICT-NDDIODE SWITCH 100V 400MW SOD123
12*****1N41481N4148W-FDICT-NDDIODE SWITCH 100V 400MW SOD123
13CD4013296-14089-1-NDIC DUAL D-TYPE FLIP-FLOP 14TSSOP1****
14CD4060296-14119-1-NDIC BNRY COUNTR/DIV 14STG 16TSSOP1****
15LM393 (half)296-14607-1-NDIC DUAL DIFF COMPARATOR 8-TSSOP1****
16TPS71518296-18731-1-NDIC LDO REG 50MA 1.8V SC70-51****
17TLV2252 (half)296-7432-5-NDIC OPAMP GP R-R 200KHZ 8TSSOP3****
18*****TLV2252 (half)296-7432-5-NDIC OPAMP GP R-R 200KHZ 8TSSOP
19*****TLV2252 (half)296-7432-5-NDIC OPAMP GP R-R 200KHZ 8TSSOP
2010K3214W-103ECT-NDTRIMPOT 10K OHM 4MM TOP ADJ SMD2****
21*****10K3214W-103ECT-NDTRIMPOT 10K OHM 4MM TOP ADJ SMD
22100K3214W-104ECT-NDTRIMPOT 100K OHM 4MM TOP ADJ SMD1****
23500K3214W-1-504ECT-NDTRIMPOT 500K OHM 4MM CERMET SMD1****
2420K3214W-203ECT-NDTRIMPOT 20K OHM 4MM TOP ADJ SMD2****
25*****20K3214W-203ECT-NDTRIMPOT 20K OHM 4MM TOP ADJ SMD
265K3214W-502ECT-NDTRIMPOT 5K OHM 4MM TOP ADJ SMD1****
27KSC241JLFS401-1762-1-NDSWITCH TACT SILVER 300GF J-LEAD2****
28*****KSC241JLFS401-1762-1-NDSWITCH TACT SILVER 300GF J-LEAD
294.8KHz433-1066-NDBUZZER 4.80KHZ 3-16BDC 85DB PCB1****
300.1F445-1317-1-NDCAP CER .10UF 16V X7R 10% 06035****
31*****0.1F445-1317-1-NDCAP CER .10UF 16V X7R 10% 0603
32*****0.1F445-1317-1-NDCAP CER .10UF 16V X7R 10% 0603
33*****0.1F445-1317-1-NDCAP CER .10UF 16V X7R 10% 0603
34*****0.1F445-1317-1-NDCAP CER .10UF 16V X7R 10% 0603
350.22uF445-1318-1-NDCAP CER .22UF 16V X7R 10% 06031****
361uF445-5138-1-NDCAP CER 1.0UF 10V X7R 06035****
37*****1uF445-5138-1-NDCAP CER 1.0UF 10V X7R 0603
38*****1uF445-5138-1-NDCAP CER 1.0UF 10V X7R 0603
39*****1F445-5138-1-NDCAP CER 1.0UF 10V X7R 0603
40*****1F445-5138-1-NDCAP CER 1.0UF 10V X7R 0603
PCB_BOM


Do you think that this can be fixed? Also, I wonder if it's easier to leave the original table where it was in columns K, L, and M and to output the counted list in columns P, Q, R, and S. Just a thought. :-)

Thanks,

Art
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,908
Members
452,949
Latest member
beartooth91

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