Hello everyone,
I got the below code from this forum only, unable to post the link. Due to the warning message "You are not allowed to post any kinds of links, images or videos until you post a few times."
Public Sub HighlightFirstOccurrence()
Dim d As Object
Dim x As Long
Dim y As Long
Dim z As Long
Dim s As String
Dim words As Variant
Dim c As Long
For y = 11 To 15000
For x = 4 To 4
s = Cells(y, x).Value
If Trim(s) <> "" Then
words = Split(s, " ")
c = 1
For z = 0 To UBound(words)
If Not d.Exists(words(z)) Then
d.Add words(z), words(z)
Cells(y, x).Characters(Start:=c, Length:=Len(words(z))).Font.Color = RGB(255, 0, 0)
End If
c = c + Len(words(z)) + 1
Next z
End If
Next x
Next y
End Sub
The above macro highlights the first occurrence of the word in red font (in column D alone). (Data is found in column D11 to E15000. Range D10 & E10 contains the header). Currently the macro takes the whole data set while highlighting, even when the filter is on and only 15 rows are visible.
Is it possible to find last row of visible cells alone (minus the header) and incorporate into the code. I want the macro to take only the visible cells into consideration while highlighting for first occurrence word. Can anybody please help ?. When i tried to include "SpecialCells(xlCellTypeVisible)", I am always getting an error. "Run time error 13, type mismatch. Please help.
Bookmarks