I'm trying to clean some records that have part numbers, category number, service type, and etc. I trying to write some vba that will delete a record based on two or more rows . The example below is scaled down. For every duplicate part number I want to delete the record if category1 and category are not 3 and 2. But if a part number does not have a category1 or category2 that are 3 and 2, then a keep the record that has 4 and 1.
There are more conditions that need to be added but I'm can't figure out how to start this. For example is the category1 and category2 equal 3 and 2 for two or more records then delete the record that has DS. But sometimes there will be records with the same PartNumber and the servicetype will be DS for all of them.
A query will also work, one that selects the records based on the same criteria used to delete. I'm drawing a blank on figuring this out.
Part_Associated | CAGE_Code | PartNumber | Category1 | Category2 | ServiceType |
3662711 | 7X677 | 53150001372582 | 3 | 2 | DA |
3662711 | 94519 | 53150001372582 | 3 | 2 | DS |
ZZ-H-428 | 81348 | 53150084144424 | 5 | 2 | DA |
28420-187B16 | 56878 | 53150084144424 | 3 | 1 | DS |
LL1/4X3/4 | 52793 | 53100059562112 | 4 | 1 | DA |
MS171657 | 96906 | 53100059562112 | 3 | 2 | DS |
MS171688 | 96906 | 53100058256776 | 3 | 1 | DA |
MS9048-104 | 96906 | 53100058256776 | 5 | 1 | DS |
There are more conditions that need to be added but I'm can't figure out how to start this. For example is the category1 and category2 equal 3 and 2 for two or more records then delete the record that has DS. But sometimes there will be records with the same PartNumber and the servicetype will be DS for all of them.
A query will also work, one that selects the records based on the same criteria used to delete. I'm drawing a blank on figuring this out.