Find a duplicate in a column.

SinKoh

New Member
Joined
Sep 29, 2016
Messages
5
Basically I have a list of part sales with the previous years sales numbers in each row. Sometimes a customer orders the same part two different times causing it to show up on the excel report twice. This is a problem because it is causing the 2017, 2016, etc data to show up twice as well. When this is turned into pivot table I have incorrect data because of the duplication. Is there a way in VBA after the sheet is populated to cycle through the part name column and if a part exists more than once set a specific range of cells to 0?
In the image below you see one part is duplicated three times. For the second and third on I need to set 2017 qty and to the right to 0.

Dw2CTDu
Dw2CTDu
Dw2CTDu
Dw2CTDu
https://imgur.com/a/Dw2CTDu
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Based on your picture and description, this is what I came up with:

Code:
Sub findDuplicates()
    Dim r As Long
    
    For r = 2 To Cells(Rows.Count, 1).End(xlUp).Row
        If Application.WorksheetFunction.CountIf(Range("A1:A" & r - 1), Cells(r, 1).Value) > 0 Then
            Range(Cells(r, 7), Cells(r, 9)).Value = 0
        End If
    Next r
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,625
Messages
6,120,598
Members
448,973
Latest member
ksonnia

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