Hello,
I have a list of products that have duplicates which have to be removed. These products correspond to serial numbers. Lower serial numbers show older products. The duplicate version that needs to be removed is the older 1. In the attached example image, we have two apples in cells B2 and B3. The older duplicate is B2 which should be removed (Entire row should be removed from the data). Similarly, Orange no 20 should be kept and other duplicates should be removed.
I am working on the following code:
Sub del_older_dups_two_col()
Dim i As Integer
Dim rng1 As Range
Dim rng2 As Range
rng1 = Range("a1:a21)
rng2 = Range("b1:b21")
For i = 1 to 20
If rng2.Cells(i, 1) = rng2.Cells(i + 1, 1) Then ' Here I need to compare each cell to the entire cells in the range
rng1.Cells(i, j).EntireRow.Delete ' Here I need to set up the condition to remove the older version
End If
Next i
End Sub
Could someone please help me complete this code.
Thank you,
Shawn
I have a list of products that have duplicates which have to be removed. These products correspond to serial numbers. Lower serial numbers show older products. The duplicate version that needs to be removed is the older 1. In the attached example image, we have two apples in cells B2 and B3. The older duplicate is B2 which should be removed (Entire row should be removed from the data). Similarly, Orange no 20 should be kept and other duplicates should be removed.
I am working on the following code:
Sub del_older_dups_two_col()
Dim i As Integer
Dim rng1 As Range
Dim rng2 As Range
rng1 = Range("a1:a21)
rng2 = Range("b1:b21")
For i = 1 to 20
If rng2.Cells(i, 1) = rng2.Cells(i + 1, 1) Then ' Here I need to compare each cell to the entire cells in the range
rng1.Cells(i, j).EntireRow.Delete ' Here I need to set up the condition to remove the older version
End If
Next i
End Sub
Could someone please help me complete this code.
Thank you,
Shawn