I have some code that I was able to piece together with the help of some online sleuthing. When the Range is F:F and I color/bold the text moving to the left (towards column A), it works like a charm.
However, if I change the Range to A:A and attempt to color/bold the text moving to the right (towards column F), it only cold/bolds the initial user inputted string? Can someone help?
Code that works
Code that doesn't work
Can someone figure out this baffling mystery?
However, if I change the Range to A:A and attempt to color/bold the text moving to the right (towards column F), it only cold/bolds the initial user inputted string? Can someone help?
Code that works
VBA Code:
Public Sub FirstRowRedText()
Set MyRange = Range("F:F") 'The Range that contains the substring you want to change color
substr = InputBox("Enter the word to make Red", , "note")
txtColor = 3 'The ColorIndex which repsents the color you want to change
For Each myString In MyRange
lenstr = Len(myString)
lensubstr = Len(substr)
For i = 1 To lenstr
tempString = Mid(myString, i, lensubstr)
If tempString = substr Then
myString.Characters(Start:=i, Length:=lensubstr).Font.ColorIndex = txtColor
myString.Characters(Start:=i, Length:=lensubstr).Font.Bold = True
myString.Offset(, -5).Resize(1, 5).Font.ColorIndex = txtColor
myString.Offset(, -5).Resize(1, 5).Font.Bold = True
End If
Next i
Next myString
Code that doesn't work
Code:
Public Sub FirstRowRedText()
Set MyRange = Range("A:A") 'The Range that contains the substring you want to change color
substr = InputBox("Enter the word to make Red", , "note")
txtColor = 3 'The ColorIndex which repsents the color you want to change
For Each myString In MyRange
lenstr = Len(myString)
lensubstr = Len(substr)
For i = 1 To lenstr
tempString = Mid(myString, i, lensubstr)
If tempString = substr Then
myString.Characters(Start:=i, Length:=lensubstr).Font.ColorIndex = txtColor
myString.Characters(Start:=i, Length:=lensubstr).Font.Bold = True
myString.Offset(, 5).Resize(1, 5).Font.ColorIndex = txtColor
myString.Offset(, 5).Resize(1, 5).Font.Bold = True
End If
Next i
Next myString
Can someone figure out this baffling mystery?