Hi, the code is written for a button on a Userform.
When clicked, it prompts the user to input words to be searched,
e.g. if "text1,text2,text3" are inputted,
the following code would start to search within the selected range and color the corresponding inputted words, "text1" , "text2", "text3" with a certain color.
However, it only succeeds in coloring the first word "text1" but not the rest.
What needs to be changed?
Thanks.
Private Sub oYellow_Click()
Call CrHL(tTxtCr.Value, wdYellow, wdColorYellow)
End Sub
' [ CrHL ]
Sub CrHL(ByVal f As String, _
ByVal HL As Long, _
ByVal Cr As Long)
Dim A As Variant
Dim rng As Range
Application.ScreenUpdating = False
'-------------------
A = Split(f, ",")
Set rng = Selection.Range
'-------------------
With rng
For i = LBound(A) To UBound(A) And .InRange(Selection.Range)
While .Find.Execute(A(i))
' Cr
Select Case ckFontCr
Case True: .Font.Color = Cr
Case False: .HighlightColorIndex = HL
End Select
Wend
Next
End With
'-------------------
Unload Me
End Sub