How to change format for an individual word in a cell

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.
 
S

StuartBisset

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top