I cannot ge to work the following code: I have a table with 2 columns. The first column stores the item name (2 possible names: 'Book' and 'Keyboard) and column 2 stores the numbers. I want to write the code according to which if there are idenitcal numbers in column 2 along both possible Item names, then the item name 'Keyboard' should dominate and all numbers in column 2 along the name 'Book' should be deleted.
This is, how the case looks before running the code:
And this is my desired outcome:
I was trying to work with the code below but it doesn't work right. I am also not sure if there should not be used another procedure like arrays?
Sub RemoveDuplicate()
Dim ws1 As Worksheet
Set ws1 = Sheets("Sheet1")
Dim cell As Range
Dim rng_delete As Range
Dim rng_Item As Range
Dim LastRow As Integer
With ws1
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
Set rng_delete = .Range(.Cells(3, 1), .Cells(LastRow, 2))
Set rng_Item = .Range(.Cells(3, 1), .Cells(LastRow, 1))
For Each cell In rng_Item
If cell.Value <> "Keyboard" Then
rng_delete.RemoveDuplicates Columns:=2, Header:=xlYes
End If
Next cell
End With
End Sub
I would appreciate any help.