So I have a macro that produces an excel sheet, part of which is a column of numbers, in order from least to greatest. There are anywhere from 1-500 duplicate numbers in this column before jumping up to the next, as in my example below
271343.53
271343.53
271343.53
271343.53
271343.53
271343.53
271343.53
271343.53
271343.53
271500
273353
273353
273353
273353
273353
273353
273353
273353
273353
274116.63
274116.63
274116.63
274116.63
274116.63
274116.63
I have a macro currently that will fill these cells in different random colors for each block of the same numbers. That macro is..
Sub HighlightDuplicates() Dim lLastRow As Long
Dim lRow As Long, lRow2 As Long
Dim rRange As Range
Dim strName As String
Dim lColor As Long
lLastRow = Cells(Rows.Count, 1).End(xlUp)(2, 1).Row
Set rRange = Range("A1:A" & lLastRow - 1)
With WorksheetFunction
For lRow = 2 To lLastRow
strName = Cells(lRow, 1)
If .CountIf(rRange, strName) > 1 Then
lRow2 = Range("A:A").Find(What:=strName, _
After:=Cells(lLastRow, 1), LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, MatchCase:=False).Row
lColor = Int((56 * Rnd) + 1)
Range(Cells(lRow, 1), Cells(lRow2, 1)).Interior.ColorIndex = lColor
lRow = lRow2
End If
Next lRow
End With
End Sub
This is great and does exactly what I want, however a lot of the randomly chosen fill colors are very dark, and currently I have to go through manually and change the font color to white. I am hoping that someone can help add to this macro to have it automatically detect when a cell's fill color is past a certain shade, and change the font color to white.
Thank you in advance and any help would be greatly appreciated!
Bookmarks