Make font colour RED of the right side numbers which are… separated by vertical bar

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,371
Office Version
  1. 2010
Using Excel 2010

Hello,

I have got numbers separated by vertical bar in the range cells B6:B25 originally they are font black.

I want is there any way to colour right side numbers which are separated by vertical bar with RED font. Like the image attached.

Excel Question ExcelFourms.xls
ABC
1
2
3
4
5
61 | 0
79 | 10
811 | 0
994 | 20
10108 | 0
11120 | 140
12136 | 40
13919 | 1
14720 | 10
15970 | 120
161029 | 1
171082 | 18
181143 | 82
191199 | 100
201262 | 102
211319 | 1212
221384 | 1789
2310015 | 17
2417225 | 175
2519230 | 1759
26
27
Sheet3


Thank you.

Regards,
Moti
 

Attachments

  • Red Fonts.png
    Red Fonts.png
    17.9 KB · Views: 6
Last edited:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
One option...
VBA Code:
Sub RedFont()
    Dim rng As Range, c As Range, i As Long, n As Long
    Set rng = Worksheets("Sheet3").Range("B6:B25")  '<~~ *** Check sheet & range ***
    For Each c In rng
        n = InStr(1, c, "|") + 1
        For i = n To Len(c)
            c.Characters(i, Len(c)).Font.Color = vbRed
        Next i
    Next c
End Sub
 
Upvote 1
If you wanted the characters bold as well...
VBA Code:
Sub RedFontBold()
    Dim rng As Range, c As Range, i As Long, n As Long
    Set rng = Worksheets("Sheet3").Range("B6:B25")  '<~~ *** Check sheet & range ***
    For Each c In rng
        n = InStr(1, c, "|") + 1
        For i = n To Len(c)
            With c.Characters(i, Len(c))
                .Font.Bold = True
                .Font.Color = vbRed
            End With
        Next i
    Next c
End Sub
 
Upvote 1
No need for the i loop as the characters are coloured all at once in the first pass of that loop. :)

VBA Code:
Sub RedFont_v2()
  Dim c As Range

  For Each c In Worksheets("Sheet3").Range("B6:B25")  '<~~ *** Check sheet & range ***
    c.Characters(InStr(1, c, "|") + 1, Len(c)).Font.Color = vbRed
  Next c
End Sub
 
Upvote 1
One option...
VBA Code:
Sub RedFont()
    Dim rng As Range, c As Range, i As Long, n As Long
    Set rng = Worksheets("Sheet3").Range("B6:B25")  '<~~ *** Check sheet & range ***
    For Each c In rng
        n = InStr(1, c, "|") + 1
        For i = n To Len(c)
            c.Characters(i, Len(c)).Font.Color = vbRed
        Next i
    Next c
End Sub
If you wanted the characters bold as well...
VBA Code:
Sub RedFontBold()
    Dim rng As Range, c As Range, i As Long, n As Long
    Set rng = Worksheets("Sheet3").Range("B6:B25")  '<~~ *** Check sheet & range ***
    For Each c In rng
        n = InStr(1, c, "|") + 1
        For i = n To Len(c)
            With c.Characters(i, Len(c))
                .Font.Bold = True
                .Font.Color = vbRed
            End With
        Next i
    Next c
End Sub

kevin9999, absolutely fine results spot on either the macro for font normal or bold.​


Thank you so much for your quick reply and time you spent for solving my question. 🤝

Good day and good luck!

Kind Regards,
Moti :)
 
Upvote 0
kevin9999, absolutely fine results spot on either the macro for font normal or bold.

Thank you so much for your quick reply and time you spent for solving my question. 🤝

Good day and good luck!

Kind Regards,
Moti :)
Happy to help Moti, but please note Peter's solution in post #4. Better option by far 👌
 
Upvote 0
No need for the i loop as the characters are coloured all at once in the first pass of that loop. :)

VBA Code:
Sub RedFont_v2()
  Dim c As Range

  For Each c In Worksheets("Sheet3").Range("B6:B25")  '<~~ *** Check sheet & range ***
    c.Characters(InStr(1, c, "|") + 1, Len(c)).Font.Color = vbRed
  Next c
End Sub
Peter_SSs, as kevin9999, said your macro is shorter and without i loop I will go with it. 🤝

I Just added 1 line to make font bold.

VBA Code:
Sub RedFont_v2()
  Dim c As Range
  For Each c In Worksheets("Sheet3").Range("B6:B25")  '<~~ *** Check sheet & range ***
    c.Characters(InStr(1, c, "|") + 1, Len(c)).Font.Color = vbRed
    c.Characters(InStr(1, c, "|") + 1, Len(c)).Font.Bold = True
  Next c
  End Sub

Thank you so much your reply and time you spent for solving my request.

Good day and good luck!

Kind Regards,
Moti :)
 
Upvote 0
I Just added 1 line to make font bold.
That is fine but this would be slightly more efficient as Instr and Len only need to be calculated once for each cell

VBA Code:
Sub RedFont_v3()
  Dim c As Range

  For Each c In Worksheets("Sheet3").Range("B6:B25")  '<~~ *** Check sheet & range ***
    With c.Characters(InStr(1, c, "|") + 1, Len(c)).Font
      .Color = vbRed
      .Bold = True
    End With
  Next c
End Sub
 
Upvote 1
That is fine but this would be slightly more efficient as Instr and Len only need to be calculated once for each cell

VBA Code:
Sub RedFont_v3()
  Dim c As Range

  For Each c In Worksheets("Sheet3").Range("B6:B25")  '<~~ *** Check sheet & range ***
    With c.Characters(InStr(1, c, "|") + 1, Len(c)).Font
      .Color = vbRed
      .Bold = True
    End With
  Next c
End Sub

Peter_SSs, yes this one is perfect! with mine added row it was screen flickering.​


I appreciate your help. 🍻 Good day and good luck!

Kind Regards,
Moti :)
 
Upvote 0
it was screen flickering.
Might be best anyway then to turn off screen updating while the process is being done.

VBA Code:
Sub RedFont_v3()
  Dim c As Range
  
  Application.ScreenUpdating = False
  For Each c In Worksheets("Sheet3").Range("B6:B25")  '<~~ *** Check sheet & range ***
    With c.Characters(InStr(1, c, "|") + 1, Len(c)).Font
      .Color = vbRed
      .Bold = True
    End With
  Next c
  Application.ScreenUpdating = True
End Sub
 
Upvote 1
Solution

Forum statistics

Threads
1,215,831
Messages
6,127,143
Members
449,363
Latest member
Yap999

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top