How do I conditionally format only some of the text in a cell?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

For example any time a cell contains the text "greater" I would like the font
for the word greater to be bold but not the other text in that cell.
 
Hi Goo

Only possible with code not with Conditional Formatting.
Do you want to use code ?
 
Go to Format / conditional formatting

in the first box, select CELL VALUE IS from the drop down.

in the second box, select EQUAL TO from the drop down.

in the third box write, GREATER (or whatever the word is)

click on Format and format the font.

I hope it helps.

GARY
 
this is the idea. modify to suit needs. Perhaps a worksheet_change event?

Sub boldwordinstring()
pos = InStr(ActiveCell, "greater")
With ActiveCell.Characters(Start:=pos, Length:=7).Font
.FontStyle = "Regular"
If pos > 0 Then
' .Name = "Courier"
.FontStyle = "Bold"
' .Size = 10
' .Underline = xlUnderlineStyleNone
' .ColorIndex = xlAutomatic
End If
End With
End Sub
 
My formula in excel contains the following formula. I am only wanting to
conditionally format the word incresed in a color. Can you tell me how to go
about doing this? Regards.

=" increased from " & TEXT(AsthmaER Previous,"0.0") & " in " & DMPrevYE &"."
 
Hi Don,

I know this post is really old but, I was wondering if you could tell me how
to modify your code below to not only change the first instance of "greater"
but, EACH instance?

Thank you for your help!
Miklo
 
'Loops through the macro until pos = 0

Sub boldwordinstring()
MyWord = ActiveCell.Value
Do
pos = InStr(MyWord, "greater")
'Keep track of where you are in the word
x = pos + x
With ActiveCell.Characters(Start:=x, Length:=7).Font
If pos > 0 Then
.FontStyle = "Bold"
End If
End With

MyWord = Mid(MyWord, pos + 1, 9999)
Loop Until pos = 0
End Sub
 
One way:

Option Explicit
Sub boldwordinstring()

Dim myWord As String
Dim Pos As Long

myWord = "greater"

Pos = 0
With ActiveCell
Do
Pos = InStr(Pos + 1, .Value, myWord, vbTextCompare)
If Pos = 0 Then
Exit Do
Else
'found another one
With .Characters(Start:=Pos, Length:=Len(myWord)).Font
.FontStyle = "bold"
End With
End If
Loop
End With
End Sub
 
Back
Top