Hi,
I am trying to write a macro which highlights the second, and all following duplicates, in a table using ListObjects
Unfortunately, it keeps returning an 'Object Required' error when arriving at the "countif" function. In the debug mode, the variable "Dupl_Cell" has a value when I hover over it, so maybe it's the variable "Name_Col"?
Here's the code:
Thanks for helping. VBA drives me NUTS!
Steve
I am trying to write a macro which highlights the second, and all following duplicates, in a table using ListObjects
Unfortunately, it keeps returning an 'Object Required' error when arriving at the "countif" function. In the debug mode, the variable "Dupl_Cell" has a value when I hover over it, so maybe it's the variable "Name_Col"?
Here's the code:
Code:
Sub Highlight_Duplicates()
Dim lotarget As ListObject
Dim Name_Col, Dupl_Rng As Range
Dim Dupl_cell As Variant
Dim TableRows As Long
Dim First_Dupl As String
Set lotarget = Worksheets("Reconcile Meds Here").ListObjects("Table3")
TableRows = lotarget.ListRows.Count
Name_Col = lotarget.Range.Columns(1)
For Each Dupl_cell In Name_Col
If WorksheetFunction.CountIf(Name_Col, Dupl_cell.Value) > 1 Then
Set Dupl_Rng = Rng.Find(What:=Dupl_cell.Value, LookIn:=xlValues)
If Not Dupl_Rng Is Nothing Then
First_Dupl = Dupl_cell.Address
Do
Set Dupl_cell = Rng.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 for helping. VBA drives me NUTS!
Steve
Last edited by a moderator: