Find & Replace in XP

J

Jewel

XP now has the ability to do a find & replace based on
formatting, but i ran across an issue. If I type the word
accountant in cell A1 and "accountants are fun" in cell
A2, do a find and replace for the word accountant that
will bold it. In cell a2 it will bold the entire cell
instead of just the word accountant, is there a way around
this if you just want the text and not the entire cell
formatted?

Thanks
 
K

Ken Wright

One way though can take a little while if a lot of text:-

Sub ColText()

Dim i As Long
Dim j As Integer
Dim k As Integer
Dim num As Long
Dim ans As String
Dim str As String

ans = InputBox("What string do you want to find")
i = Application.WorksheetFunction.CountIf(ActiveSheet.UsedRange, "*" & ans &
"*")
j = Len(ans)

Cells.Find(what:=ans, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, MatchCase:=False).Activate

For num = 1 To i
k = Application.WorksheetFunction.Find(ans, ActiveCell)
With ActiveCell.Characters(Start:=k, Length:=j).Font
.ColorIndex = 3
.Bold = True
End With
Cells.FindNext(After:=ActiveCell).Activate
Next num

End Sub

If you don't want the colour then comment out the .ColorIndex = 3 line at the
end
 

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