Sub HighlighText()
Dim RX As Object, M As Object
Set RX = CreateObject("VBScript.RegExp")
RX.Global = True
RX.Pattern = Join(Application.Transpose(Range("A1", Range("A" & Rows.Count).End(xlUp))), "|")
With Range("B1")
For Each M In RX.Execute(.Value)
.Characters(M.FirstIndex + 1, Len(M)).Font.Color = vbRed
Next M
End With
End Sub
That part is easy. Just add this lineIt is case sensitive, but I need it for both cases (Upper & Lower)
Set RX = CreateObject("VBScript.RegExp")
RX.Global = True
RX.IgnoreCase = True
If you are saying that "figurines" should also be coloured then that will require a much less efficient code. That would not be a problem if there is only one cell to process but could add significant time if there are in fact multiple cells in column B to process. Anyway, try this version.If some word index first then that word is not found with the next word. It occurs when combining 3 words where the middle word is the same. In this case, the first 2 words combine and the second and third word is not combined.
Sub HighlighText_v2()
Dim RX As Object, M As Object
Dim a As Variant, itm As Variant
Dim i As Long
Set RX = CreateObject("VBScript.RegExp")
RX.Global = True
RX.IgnoreCase = True
a = Range("A1", Range("A" & Rows.Count).End(xlUp)).Value
With Range("B1")
For i = 1 To UBound(a)
RX.Pattern = a(i, 1)
For Each M In RX.Execute(.Value)
.Characters(M.FirstIndex + 1, Len(M)).Font.Color = vbRed
Next M
Next i
End With
End Sub
What about something like this?process to execute this in multiple cells in column B or multiple columns like B, C, D....H? I need it for 8 cells
Sub HighlighText_v3()
Dim RX As Object, M As Object
Dim a As Variant, itm As Variant
Dim i As Long
Dim c As Range
Set RX = CreateObject("VBScript.RegExp")
RX.Global = True
RX.IgnoreCase = True
a = Range("A1", Range("A" & Rows.Count).End(xlUp)).Value
For Each c In Range("B1:C4")
With c
For i = 1 To UBound(a)
RX.Pattern = a(i, 1)
For Each M In RX.Execute(.Value)
.Characters(M.FirstIndex + 1, Len(M)).Font.Color = vbRed
Next M
Next i
End With
Next c
End Sub