floggingmolly
Board Regular
- Joined
- Sep 14, 2019
- Messages
- 167
- Office Version
- 365
- Platform
- Windows
I have a VBA code that colors duplicates with different colors. This works, but when I convert the range to a table it no longer works. Can anyone assist with adjusting this code to work with a table? Any help would be greatly appreciated.
Code:
Sub ColorDupsRGB()
Dim a As Variant, ky As Variant
Dim dic As Object, r As Range, i As Long, nColor As String
Application.ScreenUpdating = False
Set r = Range("A3:H" & Range("A" & Rows.Count).End(xlUp).Row)
r.Interior.ColorIndex = xlNone
a = Application.Index(r.Value2, , 1)
Set dic = CreateObject("Scripting.Dictionary")
dic.CompareMode = vbTextCompare
For i = 1 To UBound(a)
dic(a(i, 1)) = dic(a(i, 1)) + 1
Next
nColor = 300000000
For Each ky In dic.keys
If dic(ky) > 1 Then
r.Offset(-1).AutoFilter 1, ky
ActiveSheet.AutoFilter.Range.Offset(1).Interior.Color = nColor
nColor = nColor + 1000000
End If
Next
If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
r.Offset(r.Rows.Count).Resize(1).Interior.Color = xlNone
End Sub