I am iterating trough a range and want to highlight the repeating ones.
I tried to write a sub that checks if any value in a range repeats itself, and if it does, I want to highlight it
Later on I want to check if that value repeats itself more than x times (but that is straight forward, just add a counter and increment it)
I tried using two different methods
Method 1
Sub Highlight()
Dim count, countMax As Integer
countMax = 100
Dim rng As range, cell As range
Set rng = range("G1:G100")
For Each cell In rng
For count = 1 To countMax
Selection.Offset(1, 0).Select
If Not IsEmpty(cell) And cell.Value = Selection.Value Then
cell.Interior.color = RGB(0, 255, 0)
End If
countMax = countMax - 1
Next count
Next cell
End Sub
Method 2
Sub Highlight()
Dim rngG1 As range, cellG1 As range
Set rngG1 = range("G1:G100")
Dim rngG2 As range, cellG2 As range
Set rngG2 = range("G1:G100")
For Each cellG1 In rngG1
For Each cellG2 In rngG2
If cellG1 <> cellG2 And Not IsEmpty(cellG1) And cellG1.Value = cellG2.Value Then
cellG2.Interior.color = RGB(0, 255, 0)
End If
Next cellG2
Next cellG1
End Sub
Both methods don't highlight anything, please help with some information or point me in a direction.
Thanks.