+ Reply to Thread
Results 1 to 23 of 23

Macro that will turn any text (bracketed) to red

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-15-2013
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    218

    Macro that will turn any text (bracketed) to red

    Hello All,

    I created two condition formats for the range of G1017:G4007 to turn certain text red.

    First Condition format, if cell contains text "No EN Worker Category", works so no need to change this unless the macro will effect this.

    The second Condition format is what I would like to be replaced with a macro. I want any text in (bracketed) to turn red and only the text in (brackets).

    Attached excel sheet for your reference. EN BG Report (Master) v2.2.3.xlsm

    In column M, I made a example of what the macro should do. In row 1037 and 1051 only the (bracketed) is red while the rest remains black.

    Hope this was clear.

    Thanks,

    Jason

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,777

    Re: Macro that will turn any text (bracketed) to red

    Add this code to the Sheet module for Sheet1 (Group Leader Summary). I have tested this.

    Private Sub Worksheet_Change(ByVal Target As Range)
    
       Dim C As Range
       
       For Each C In Target
          C.Font.Color = RGB(0, 0, 0)
          PaintParens C
       Next C
       
    End Sub
    
    Private Sub PaintParens(C As Range)
       
       Dim SStart As Long
       Dim SEnd As Long
          
       SStart = 1
       
       Do While SStart < Len(C.Value)
       
          Do While SStart < Len(C.Value) And Mid(C.Value, SStart, 1) <> "("
             SStart = SStart + 1
          Loop
          
          If SStart < Len(C.Value) Then
             SEnd = SStart + 1
             Do While SEnd < Len(C.Value) And Mid(C.Value, SEnd, 1) <> ")"
                SEnd = SEnd + 1
             Loop
             If SEnd > Len(C.Value) Then
                MsgBox ("Mismatched parentheses in " & C.Address & " =" & C.Value)
             Else
                C.Characters(Start:=SStart, Length:=SEnd - SStart + 1).Font.Color = RGB(255, 0, 0)
             End If
          End If
          
          SStart = SStart + 1
       Loop
    
    End Sub
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    10-15-2013
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    218

    Re: Macro that will turn any text (bracketed) to red

    Quote Originally Posted by 6StringJazzer View Post
    Add this code to the Sheet module for Sheet1 (Group Leader Summary). I have tested this.

    Private Sub Worksheet_Change(ByVal Target As Range)
    
       Dim C As Range
       
       For Each C In Target
          C.Font.Color = RGB(0, 0, 0)
          PaintParens C
       Next C
       
    End Sub
    
    Private Sub PaintParens(C As Range)
       
       Dim SStart As Long
       Dim SEnd As Long
          
       SStart = 1
       
       Do While SStart < Len(C.Value)
       
          Do While SStart < Len(C.Value) And Mid(C.Value, SStart, 1) <> "("
             SStart = SStart + 1
          Loop
          
          If SStart < Len(C.Value) Then
             SEnd = SStart + 1
             Do While SEnd < Len(C.Value) And Mid(C.Value, SEnd, 1) <> ")"
                SEnd = SEnd + 1
             Loop
             If SEnd > Len(C.Value) Then
                MsgBox ("Mismatched parentheses in " & C.Address & " =" & C.Value)
             Else
                C.Characters(Start:=SStart, Length:=SEnd - SStart + 1).Font.Color = RGB(255, 0, 0)
             End If
          End If
          
          SStart = SStart + 1
       Loop
    
    End Sub
    Thanks Jeff,

    I pasted this into a module... but how do i run this? I don't see it in the list of macro's to run.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,777

    Re: Macro that will turn any text (bracketed) to red

    You can't just paste it into a module, you must paste it into the module for the sheet containing this data.

    It will run automatically any time a cell on that sheet is changed.

  5. #5
    Forum Contributor
    Join Date
    10-15-2013
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    218

    Re: Macro that will turn any text (bracketed) to red

    Quote Originally Posted by 6StringJazzer View Post
    You can't just paste it into a module, you must paste it into the module for the sheet containing this data.

    It will run automatically any time a cell on that sheet is changed.
    Thanks 6StringJazzer,

    I pasted it into the sheet and seemed to work but it doesn't as I only want the (bracketed) text to turn red. Also there were some anomalies...

    Example: "HWWL (PMSS) SAW" would remain all black, but I want the "PMSS" to turn red.
    Example: "(PMSS) SC-HW" would turn all red, but I want the "SC-HW" to remain black.

    Thanks,

  6. #6
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Macro that will turn any text (bracketed) to red

    Hi Jason
    The worksheet change code below will do what you want for the range in Column M on your example. It will change the text colour to red from the first "(" in a cell to the last ")" in a cell. I don't know if you want to restrict it to a range or do the whole sheet. Copy & paste it into the sheet module to test.

    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 = InStr(Bracket2 + 1, Target, B2) ' Test for a 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 a 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

  7. #7
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Macro that will turn any text (bracketed) to red

    Here is some code that will loop through column M & colour the cell text as desired. Put it in a normal module & call the macro from a button.

    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 = InStr(Bracket2 + 1, 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

  8. #8
    Forum Contributor
    Join Date
    10-15-2013
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    218

    Re: Macro that will turn any text (bracketed) to red

    Quote Originally Posted by Philb1 View Post
    Here is some code that will loop through column M & colour the cell text as desired. Put it in a normal module & call the macro from a button.

    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 = InStr(Bracket2 + 1, 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
    Thanks Philb1,

    Two options... nice.

    I tried the Macro one and works... but I noticed a couple anomalies...

    for "(OER) (SC-C) (SC-HW)" , the "(OER) (SC-C)" would be red and the (SC-HW) is still black.
    for "HWWL (PMSS) SAW" , the "(PMSS) SAW" would be red; not sure why it didn't see the end bracket?

    I also noticed this turns the whole line red if it is a reference from another location. ie; ='Sheer1'!A1 as opposed to the text typed out as "xxx (xxx) xxx". This isn't a big issue but be nice to be able to use on a reference.
    Last edited by JasonNeedsHelp; 11-20-2015 at 06:48 PM.

  9. #9
    Forum Contributor amartinez988's Avatar
    Join Date
    05-04-2015
    Location
    Miami
    MS-Off Ver
    Office 2010
    Posts
    183

    Re: Macro that will turn any text (bracketed) to red

    I know that you have the answers already, but just as an addiction, you could also use CONDITIONAL FORMATTING for this. Works fast and easy to do.
    If you are interested let me know

  10. #10
    Forum Contributor
    Join Date
    10-15-2013
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    218

    Re: Macro that will turn any text (bracketed) to red

    Quote Originally Posted by amartinez988 View Post
    I know that you have the answers already, but just as an addiction, you could also use CONDITIONAL FORMATTING for this. Works fast and easy to do.
    If you are interested let me know
    Hi amartinez,

    Yes, I know. But the challenge is that I only want part of the text to be red not the whole cell. Condition Format effects the whole cell.

  11. #11
    Forum Contributor amartinez988's Avatar
    Join Date
    05-04-2015
    Location
    Miami
    MS-Off Ver
    Office 2010
    Posts
    183

    Re: Macro that will turn any text (bracketed) to red

    Got you!

  12. #12
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: Macro that will turn any text (bracketed) to red

    Integrate this part of the code and it will work

    Sub testing()
    Dim l   As Integer
    Dim i   As Integer
    Dim r   As Boolean
    l = Len(ActiveCell.Value)
    For i = 1 To l
        If Mid(ActiveCell.Value, i, 1) = ")" Then r = False
        With ActiveCell.Characters(Start:=i, Length:=1).Font
            Select Case r
            Case Is = True
                .Color = vbRed
            Case Else
                .Color = vbBlack
            End Select
        End With
        If Mid(ActiveCell.Value, i, 1) = "(" Then r = True
        If Mid(ActiveCell.Value, i, 1) = ")" Then r = False
    Next i
    End Sub
    Place the module the worksheet, select a cell in your column M and then run this macro
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,633

    Re: Macro that will turn any text (bracketed) to red

    1) You need to delete 1st conditional format otherwise it overrides changes by macro.
    2) You can either call "test" macro my selecting "test" via Alt + F8 or just change the cell(s).

    To a sheet code module
    Private Sub Worksheet_Change(ByVal Target As Range)
        Set myRng = Intersect(Target, Range("G1017:G4007"))
        If Not myRng Is Nothing Then test
        Set myRng = Nothing
    End Sub
    To a Standard code module
    Option Explicit
    Public myRng As Range
    
    Sub test()
        Dim r As Range, m As Object
        If myRng Is Nothing Then Set myRng = Sheets("Group Leader Summary").Range("G1017:G4007")
        myRng.Font.ColorIndex = xlAutomatic
        With CreateObject("VBScript.RegExp")
            .Global = True
            .Pattern = "\([^\)]+(?=\))"
            For Each r In myRng
                For Each m In .Execute(r.Value)
                    r.Characters(m.firstindex + 2, m.Length - 1).Font.Color = vbRed
                Next
            Next
        End With
    End Sub
    See attached.
    Attached Files Attached Files
    Last edited by jindon; 11-20-2015 at 07:23 PM. Reason: Fixed typo

  14. #14
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Macro that will turn any text (bracketed) to red

    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

  15. #15
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Macro that will turn any text (bracketed) to red

    Shorter versions below.
    I've been thinking of doing something like this to one of my journal books & until now, have been to lazy lol. Killed 2 birds with 1 stone

    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
    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) ' First opening bracket position
        Bracket2 = InStrRev(rCell, B2) ' Last closing bracket position
        
        If Not Bracket1 = 0 And Not Bracket2 = 0 Then
        
            rCell.Characters(Bracket1, Bracket2).Font.Color = vbRed
        
        End If
    
    Next rCell
    
    Application.ScreenUpdating = True
    
    Exit Sub
    
    End Sub
    Private Sub Worksheet_Change(ByVal Target As Range) ' Column M only
    
    Dim Bracket1 As Long, Bracket2 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) ' First Opening bracket position
            Bracket2 = InStrRev(Target, B2) ' Last closing bracket position
    
            If Not Bracket1 = 0 And Not Bracket2 = 0 Then
    
                Target.Characters(Bracket1, Bracket2).Font.Color = vbRed
    
            End If
            
        End If
            Application.EnableEvents = True
            Application.ScreenUpdating = True
        Exit Sub
    
    ErrorOut:
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    Exit Sub
    
    End Sub

  16. #16
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,642

    Re: Macro that will turn any text (bracketed) to red

    Option Explicit
    Sub Black2Red()
        Dim StrLen          As Long, _
            StrtPos         As Long, _
            k               As Long, _
            rpl             As String, _
            LeftRightPos    As Variant
        
        StrLen = Len(Range("L1").Value)
        rpl = Replace(Range("L1").Value, "(", "")
        StrtPos = Len(rpl)
        StrLen = StrLen - StrtPos
        ReDim LeftRightPos(1 To StrLen, 1 To 2)
        StrtPos = 1
        For k = 1 To StrLen
            LeftRightPos(k, 1) = InStr(StrtPos, Range("L1").Value, "(")
            LeftRightPos(k, 2) = InStr(LeftRightPos(k, 1), Range("L1").Value, ")")
            Range("L1").Characters(Start:=LeftRightPos(k, 1) + 1, Length:=LeftRightPos(k, 2) - LeftRightPos(k, 1) - 1).Font.Color = vbRed
            StrtPos = LeftRightPos(k, 2) - 1
        Next k
    End Sub
    Ben Van Johnson

  17. #17
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Macro that will turn any text (bracketed) to red

    Nice code ProtonLeah.
    I thought about doing what you've done but I didn't know how to do it. I've worked out how your code works & now I do.
    Thanks
    Phil

  18. #18
    Forum Contributor
    Join Date
    10-15-2013
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    218

    Re: Macro that will turn any text (bracketed) to red

    Quote Originally Posted by protonLeah View Post
    Option Explicit
    Sub Black2Red()
        Dim StrLen          As Long, _
            StrtPos         As Long, _
            k               As Long, _
            rpl             As String, _
            LeftRightPos    As Variant
        
        StrLen = Len(Range("L1").Value)
        rpl = Replace(Range("L1").Value, "(", "")
        StrtPos = Len(rpl)
        StrLen = StrLen - StrtPos
        ReDim LeftRightPos(1 To StrLen, 1 To 2)
        StrtPos = 1
        For k = 1 To StrLen
            LeftRightPos(k, 1) = InStr(StrtPos, Range("L1").Value, "(")
            LeftRightPos(k, 2) = InStr(LeftRightPos(k, 1), Range("L1").Value, ")")
            Range("L1").Characters(Start:=LeftRightPos(k, 1) + 1, Length:=LeftRightPos(k, 2) - LeftRightPos(k, 1) - 1).Font.Color = vbRed
            StrtPos = LeftRightPos(k, 2) - 1
        Next k
    End Sub
    Not sure why.. but recieved a debug on

    ReDim LeftRightPos(1 To StrLen, 1 To 2)

  19. #19
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,642

    Re: Macro that will turn any text (bracketed) to red

    Philb1,
    Thank you

  20. #20
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: Macro that will turn any text (bracketed) to red

    Anybody take a look at this at all?

    Public Sub RedTextModified()
    Application.ScreenUpdating = False
    
    Dim Ws1 As Worksheet: Set Ws1 = ThisWorkbook.Sheets(1)
    Dim rCell As Range
    Dim l   As Integer
    Dim i   As Integer
    Dim r   As Boolean
    
    '   Column M is 13th column, change to suit
    For Each rCell In Ws1.Range(Ws1.Cells(1, 13), Ws1.Cells(Rows.Count, 13).End(xlUp))
        l = Len(rCell.Value)
        For i = 1 To l
            If Mid(rCell.Value, i, 1) = ")" Then r = False
            With rCell.Characters(Start:=i, Length:=1).Font
                Select Case r
                Case Is = True
                    .Color = vbRed
                Case Else
                    .Color = vbBlack
                End Select
            End With
            If Mid(rCell.Value, i, 1) = "(" Then r = True
        Next i
    Next rCell
    Application.ScreenUpdating = True
    End Sub
    There are more than one ocurrences (...) (...)
    This works

  21. #21
    Forum Contributor
    Join Date
    10-15-2013
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    218

    Re: Macro that will turn any text (bracketed) to red

    Thanks All!

    I tried all of these and they all seem to work. Now i just need to decide which one...

    Thanks again!

  22. #22
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,633

    Re: Macro that will turn any text (bracketed) to red

    Perhaps easiest to understand.
    Sub test()
        Dim r As Range, x As Long, y As Long
        If myRng Is Nothing Then Set myRng = Sheets("Group Leader Summary").Range("G1017:G4007")
        myRng.Font.ColorIndex = xlAutomatic
        For Each r In myRng
            y = InStrRev(r.Value, ")")
            Do While y
                x = InStrRev(r.Value, "(", y)
                If x Then
                    r.Characters(x + 1, y - x).Font.Color = vbRed
                End If
                y = InStrRev(r.Value, ")", x)
            Loop
        Next
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Sum multiple bracketed values in the same cell
    By dobraf in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 04-03-2014, 07:01 PM
  2. Insert a blank row before bracketed text
    By bvlahides in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-04-2013, 08:19 PM
  3. Create 1 by 2 bracketed matrix in Excel
    By Coukapecker in forum Excel General
    Replies: 0
    Last Post: 09-28-2011, 01:02 PM
  4. Loop all cells to remove bracketed text
    By gcoug in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-29-2011, 04:38 PM
  5. Replies: 3
    Last Post: 06-02-2011, 11:03 AM
  6. Replies: 3
    Last Post: 08-23-2005, 05:05 PM
  7. BRACKETED NEGATIVE NUMBERS IN EXCEL
    By Bushco in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 02-11-2005, 10:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1