This will find the last ")" & colour all the text in between the first "(" & the last ")" red
Private Sub Worksheet_Change(ByVal Target As Range) ' Column M only
Dim Bracket1 As Long, Bracket2 As Long, Bracket3 As Long
Dim RedTextRange As Range
Dim B1 As String, B2 As String
B1 = "("
B2 = ")"
Set RedTextRange = Me.Range(Me.Cells(1017, 13), Me.Cells(Rows.Count, 13).End(xlUp))
On Error GoTo ErrorOut
' Anything outside the target range, do nothing
If Intersect(Target, RedTextRange) Is Nothing Then
Exit Sub
' Anything in the target range
ElseIf Not Intersect(Target, RedTextRange) Is Nothing Then
Application.ScreenUpdating = False
Application.EnableEvents = False
Bracket1 = InStr(Target, B1) ' Beginning bracket position
Bracket2 = InStr(Target, B2) ' Ending bracket position
Bracket3 = InStrRev(rCell, B2) ' Test for another ending bracket position
If Not Bracket1 = 0 And Not Bracket2 = 0 Then
If Bracket3 = 0 Then
Target.Characters(Bracket1, Bracket2).Font.Color = vbRed
Else ' If there is another ending bracket, red text between 1st & last bracket
Target.Characters(Bracket1, Bracket3).Font.Color = vbRed
End If
End If
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
Exit Sub
ErrorOut:
Application.EnableEvents = True
Application.ScreenUpdating = True
Exit Sub
End Sub
Option Explicit
Sub RedText()
Application.ScreenUpdating = False
Dim Ws1 As Worksheet: Set Ws1 = ThisWorkbook.Sheets(1)
Dim rCell As Range
Dim Bracket1 As Long, Bracket2 As Long, Bracket3 As Long
Dim B1 As String, B2 As String
B1 = "("
B2 = ")"
' Column M is 13th column, change to suit
For Each rCell In Ws1.Range(Ws1.Cells(1017, 13), Ws1.Cells(Rows.Count, 13).End(xlUp))
Bracket1 = InStr(rCell, B1) ' Beginning bracket position
Bracket2 = InStr(rCell, B2) ' Ending bracket position
Bracket3 = InStrRev(rCell, B2) ' Test for a another ending bracket position
If Not Bracket1 = 0 And Not Bracket2 = 0 Then
If Bracket3 = 0 Then
rCell.Characters(Bracket1, Bracket2).Font.Color = vbRed
Else ' If there is a another ending bracket, red text between 1st & last bracket
rCell.Characters(Bracket1, Bracket3).Font.Color = vbRed
End If
End If
Next rCell
Application.ScreenUpdating = True
Exit Sub
End Sub
Bookmarks