Hi again,
Thank you to those heroes that helped me with my question earlier today, but I've got another one.
I'm trying to get this macro to highlight ONLY the 2nd, 3rd, 4th etc instance of a duplicate. I've since reverted to the original formula, but adding in a For...Each counter didn't seem to make any difference, nor did playing around with the placement of the color change.
Here's the code:
Sub Highlight_Duplicates()
Dim lotarget As ListObject
Dim Name_Col As Range, Dupl_Rng As Range
Dim Dupl_cell As Range
Dim TableRows As Long
Dim First_Dupl As String
Set lotarget = Worksheets("Reconcile Meds Here").ListObjects("Table3")
TableRows = lotarget.ListRows.Count
Set Name_Col = lotarget.Range.Columns(1)
Range("C7:c200").ClearFormats
lotarget.TableStyle = "TableStyleMedium2"
For Each Dupl_cell In Name_Col.Cells
If WorksheetFunction.CountIf(Name_Col, Dupl_cell.Value) > 1 Then
Set Dupl_Rng = Name_Col.Find(What:=Dupl_cell.Value, LookIn:=xlValues)
If Not Dupl_Rng Is Nothing Then
First_Dupl = Dupl_cell.Address
Do
Set Dupl_cell = Name_Col.FindNext(Dupl_cell)
Dupl_cell.Interior.ColorIndex = 35
Loop While Not Dupl_cell Is Nothing And Dupl_cell.Address <> First_Dupl
End If
End If
Next
End Sub
Thanks again!
Thank you to those heroes that helped me with my question earlier today, but I've got another one.
I'm trying to get this macro to highlight ONLY the 2nd, 3rd, 4th etc instance of a duplicate. I've since reverted to the original formula, but adding in a For...Each counter didn't seem to make any difference, nor did playing around with the placement of the color change.
Here's the code:
Sub Highlight_Duplicates()
Dim lotarget As ListObject
Dim Name_Col As Range, Dupl_Rng As Range
Dim Dupl_cell As Range
Dim TableRows As Long
Dim First_Dupl As String
Set lotarget = Worksheets("Reconcile Meds Here").ListObjects("Table3")
TableRows = lotarget.ListRows.Count
Set Name_Col = lotarget.Range.Columns(1)
Range("C7:c200").ClearFormats
lotarget.TableStyle = "TableStyleMedium2"
For Each Dupl_cell In Name_Col.Cells
If WorksheetFunction.CountIf(Name_Col, Dupl_cell.Value) > 1 Then
Set Dupl_Rng = Name_Col.Find(What:=Dupl_cell.Value, LookIn:=xlValues)
If Not Dupl_Rng Is Nothing Then
First_Dupl = Dupl_cell.Address
Do
Set Dupl_cell = Name_Col.FindNext(Dupl_cell)
Dupl_cell.Interior.ColorIndex = 35
Loop While Not Dupl_cell Is Nothing And Dupl_cell.Address <> First_Dupl
End If
End If
Next
End Sub
Thanks again!