It suppose to color the words only if the original word in brackets are colored....
Change to this.
It will strip the words in brackets and color them in red.
Sub RmBrackets()
Dim r As Range, x(), i As Long
With CreateObject("VBScript.RegExp")
.Global = True
For Each r In Range("L22")
If r.Address = r.MergeArea.Cells(1).Address Then
.Pattern = "(\[)([^\[\]]+)(\])"
If .test(r.Value) Then
ReDim x(1 To .Execute(r.Value).Count, 1 To 3)
For i = 0 To .Execute(r.Value).Count - 1
x(i + 1, 1) = .Execute(r.Value)(i).firstindex + 1 - i * 2
x(i + 1, 2) = .Execute(r.Value)(i).Length - 2
x(i + 1, 3) = r.Characters(.Execute(r.Value)(i) _
.firstindex + 2, 1).Font.Color
Next
r.Value = .Replace(r.Value, Chr(2) & "$2" & Chr(2))
.Pattern = Chr(2)
r.Value = .Replace(r.Value, "")
For i = 1 To UBound(x, 1)
r.Characters(x(i, 1), x(i, 2)).Font.Color = vbRed
Next
End If
End If
Next
End With
End Sub
Bookmarks