Conditionally-like formatting just a part of a cell
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
|