Code amendment for changing text colour in a cell

asylum

Board Regular
Joined
Dec 2, 2003
Messages
243
Hello,

I have the below text that looks in a range of cells and changes BH: to bold if it finds it present. However I want to amend this to achieve three things:

The BH: is always the first thing in the cell (if present) and is followed by some text and a comma then some other text ie:

BH: string1, blah, blah, blahblah

What I want to do is, if BH: starts the cell then to-

1) make everthing before (and including) the first comma Bold, (in black already)
2) turn all text after the comma to red,
3) Highight the cell in light grey,

any thoughts? Thanks

Sub BH()

Dim R As Range

Sheets("one").Select

For Each R In Range("d1:d380")
If InStr(1, R.Value, "BH:", 1) Then
For i = 1 To Len(R.Value)
If R.Characters(Start:=i, Length:=3).Text = "BH:" Then _
R.Characters(Start:=i, Length:=3).Font.Bold = True
Next i
End If
Next R

End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi

Try:

Code:
Sub BH()
Dim R As Range
Dim j As Long
 
For Each R In Worksheets("one").Range("d1:d380")
    If R.Value Like "BH:*,*" Then
        j = InStr(R.Value, ",")
        R.Characters(Start:=1, Length:=j).Font.Bold = True
        R.Characters(Start:=j + 1).Font.Color = vbRed
        R.Interior.Color = RGB(224, 224, 224)
    End If
Next R
End Sub
 
Upvote 0
Hi,

small problem it actaully turns the cell white, but thats an easy one to fix, however its turning the whole cells text bold black here, not half bold black and teh rest normal red??
 
Upvote 0
got it! (see below) tahnks for your help!

Sub BH()
Dim R As Range
Dim j As Long

For Each R In Worksheets("Calendar").Range("d1:d380")
If R.Value Like "BH:*,*" Then
j = InStr(R.Value, ",")
R.Characters(Start:=1, Length:=j).Font.Bold = True
R.Characters(Start:=j + 1).Font.ColorIndex = 3
R.Interior.Color = RGB(224, 224, 224)
End If
Next R

End Sub
 
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