Changing Text Color

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
Hi,

I am trying to change font color if there is a ^ in front of the text. I have created a code below but can't seem to get it to work

VBA Code:
Private Sub Fill_Colour_Click()

Dim c As Range, x As Long
Dim ws As Worksheet

Set ws = Sheets("Job Card Master")
Set c = ws.Range("E13:E307")

For Each c In Selection
    If Right(c, 1) = Chr("^") Then c = Left(c, Len(c) - 1)
    If InStr(c, Chr("^")) > 0 Then
        c.Value = c.Value
        For x = 1 To Len(c)
            If Asc(Mid(c, x, 1)) = Chr("^") Then c.Characters(x, 1).vbRed
        Next
    End If
Next
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hello.
Try this one:
VBA Code:
Private Sub Fill_Colour_Click()

Dim c As Range, x As Long
Dim ws As Worksheet

Set ws = Sheets("Job Card Master")
Set c = ws.Range("E13:E307")

For Each c In Selection

'If ends whit a "^" then font color = to red
If Right(c, 1) = "^" Then
c.Font.Color = vbRed
'Else no ends whit a "^" then font color = to black
Else
c.Font.Color = vbBlack
End If
Next

End Sub
 
Upvote 0
Hello.
Try this one:
VBA Code:
Private Sub Fill_Colour_Click()

Dim c As Range, x As Long
Dim ws As Worksheet

Set ws = Sheets("Job Card Master")
Set c = ws.Range("E13:E307")

For Each c In Selection

'If ends whit a "^" then font color = to red
If Right(c, 1) = "^" Then
c.Font.Color = vbRed
'Else no ends whit a "^" then font color = to black
Else
c.Font.Color = vbBlack
End If
Next

End Sub
I`ve tried this but it jumps over the code if I try to run using F8. The text is to start with ^ rather than end with ^.
 
Upvote 0
Try this:
VBA Code:
Private Sub Fill_Colour_Click()

Dim c As Range, x As Long
Dim ws As Worksheet

Set ws = Sheets("Job Card Master")
Set c = ws.Range("E13:E307")

For Each c In Range("E13:E307")

'If begins whit a "^" then font color = to red
If Left(c, 1) = "^" Then
c.Font.Color = vbRed
'Else font color = to black
Else
c.Font.Color = vbBlack
End If
Next

End Sub

He runs for me here
 
Upvote 0
Solution
Thanks just ideal works brillant
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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