Hi this is my first post - I don't think it will be too difficult for you guys but I have only recently started to learn VBA!
I found the below code from searching the web and have tried adapting it without success as I could not find any code to fit my exact purpose.
This code finds any string in a cell of your choice and colors it red. I would really like to replace the string with my own string of text. I couldn't use the simple find and replace function as this replaces the WHOLE cell content not just one word.
I believe the line of code that needs editing most is this one
Do
Found.Characters(Counter, Len(FindWhat)).Font.ColorIndex = MyColor
Counter = InStr(Counter + 1, LCase(Found), FindWhat)
But I cannot figure out how to use the replace function with this. Very grateful for any enlightenment!
I found the below code from searching the web and have tried adapting it without success as I could not find any code to fit my exact purpose.
Code:
Sub Colorize_Word()
Dim Found As Range, FirstFound As String
Dim FindWhat As String, MyColor As Long, Counter As Integer
MyColor = 3
FindWhat = LCase(InputBox("Find what word?", "Color word"))
If FindWhat = "" Then Exit Sub
Set Found = Cells.Find(What:=FindWhat, _
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, _
SearchFormat:=False)
If Not Found Is Nothing Then
FirstFound = Found.Address
Application.ScreenUpdating = False
Do
Set Found = Cells.FindNext(Found)
Counter = InStr(LCase(Found), FindWhat)
Do
Found.Characters(Counter, Len(FindWhat)).Font.ColorIndex = MyColor
Counter = InStr(Counter + 1, LCase(Found), FindWhat)
Loop While Counter > 0
Loop Until Found.Address = FirstFound
Application.ScreenUpdating = True
Else
MsgBox "No match found."
End If
End Sub
This code finds any string in a cell of your choice and colors it red. I would really like to replace the string with my own string of text. I couldn't use the simple find and replace function as this replaces the WHOLE cell content not just one word.
I believe the line of code that needs editing most is this one
Do
Found.Characters(Counter, Len(FindWhat)).Font.ColorIndex = MyColor
Counter = InStr(Counter + 1, LCase(Found), FindWhat)
But I cannot figure out how to use the replace function with this. Very grateful for any enlightenment!