Conditionally-like formatting just a part of a cell
Excellent, OssieMac! That is it, thank you! One more point - what would be
the best way to unset any previous formatting before proceeding with the
next? Is there e.g. a function to do like 'take range a1:e10 and clear all
formatting'?
"OssieMac" wrote:
My apologies Mac,
I forgot to change the hard coded "eel" in the find code to the variable
that I created. Use the following instead.
Sub FindAndFormat()
Dim rngToSearch As Range
Dim rngToFind As Range
Dim strToFind As String
Dim strFirstAddr As String
Dim intFirstChr As Integer
Dim intLenStr As Integer
strToFind = Sheets("Sheet1").Range("F1")
intLenStr = Len(strToFind)
With Sheets("Sheet1")
Set rngToSearch = .Range("A1:E10")
End With
With rngToSearch
Set rngToFind = .Find(What:=strToFind, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If Not rngToFind Is Nothing Then
strFirstAddr = rngToFind.Address
Do
rngToFind.Characters _
(InStr(1, rngToFind.Value, strToFind), intLenStr) _
.Font.Bold = True
rngToFind.Characters _
(InStr(1, rngToFind.Value, strToFind), intLenStr) _
.Font.Color = vbRed
Set rngToFind = .FindNext(rngToFind)
Loop While Not rngToFind Is Nothing _
And rngToFind.Address < strFirstAddr
End If
End With
End Sub
--
Regards,
OssieMac
|