Format cell characters with Find method (VBA)

Craig__

Board Regular
Joined
Feb 16, 2010
Messages
66
How can I modify the code below to format all characters from the found word "over" right through to the last character in the cell. Neither the number of characters before or after the found word are constant, so using something like Start:=11, Length:=27 would not work.

Thanks for your help.


Sub Format_Characters_In_Found_Cell()

x = "over"
Set Found = Cells.Find(what:=x, LookIn:=xlValues, LookAt:=xlPart)
If Found Is Nothing Then
MsgBox x & " could not be found.", , " "
Else

'Format last character in found cell
' Found.Characters(Start:=Len(Found), Length:=Len(ActiveCell)).Font.ColorIndex = 5

'Format all characters in found cell
' Found.Characters(Start:=Len(ActiveCell), Length:=Len(Found)).Font.ColorIndex = 5

'Format 11th character in found cell through to last character in found cell
' Found.Characters(Start:=11, Length:=Len(ActiveCell)).Font.ColorIndex = 5

End If
End Sub
 
Find cells containing the word "over" then format all characters from the letter r in "over" backwards to the first character at the beginning of the cell.

For example:
If found cell contains "DZ81 over 60" format all characters from r backwards to D
If found cell contains "QH490 over 50" format all characters from r backwards to Q
If found cell contains "YSG3551 over 30" format all characters from r backwards to Y
If found cell contains "TC9242091 over 20" format all characters from r backwards to T
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,224,518
Messages
6,179,256
Members
452,901
Latest member
LisaGo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top