How to change format for an individual word in a cell

  • Thread starter Thread starter jaysan3
  • Start date Start date
J

jaysan3

Hi,
I would like to change bold a single word in a cell that has multiple words.
I tried to use find and replace, but the whole cell is bold instead.

Example: B1 contains "Washington Apples". I want to bold all the "Apples"
found in the worksheet.
 
Hi Jaysan

Try using this macro. All you would do is select a worksheet, run the
macro, enter the word you want to make Bold then click ok. It will
find the word anywhere in the sheet and make it bold.

Hope this helps

Sub BoldChosenWord()
Dim rng As Range
Dim xloop As Long
Dim cll As Long
Dim word As String
Dim wordLength As Long
Dim CllText As Variant
Dim wordStart As Long

Set rng = ActiveSheet.UsedRange
cll = rng.Count

word = InputBox("What word?", "Bold A Word", vbOKCancel)

If word = "" Then Exit Sub
wordLength = Len(word)

For xloop = 1 To cll
CllText = rng.Item(xloop)
If InStr(CllText, word) > 0 Then
wordStart = InStr(CllText, word)
rng.Item(xloop).Characters(Start:=wordStart,
Length:=wordLength). _
Font.FontStyle = "Bold"
End If
Next xloop

End Sub


Stuart
www.insightmodelling.co.uk
 
Back
Top