Ok, this is one step closer to something you are doing:
Sub WorksheetLoop()
Dim WS_Count As Integer
Dim I As Integer
Dim varFound As Variant, varSearch As Variant
Dim strAddress As String, intPos As Integer
WS_Count = ActiveWorkbook.Worksheets.Count
For I = 1 To WS_Count
varSearch = "CUS_ECO_SEC_CD"
Set varFound = Cells.Find(varSearch, LookIn:=xlValues, LookAt:=xlPart)
If Not varFound Is Nothing Then
strAddress = varFound.Address
With varFound
Do
intPos = InStr(intPos + 1, .Value, varSearch, vbTextCompare)
If intPos Then
.Characters(Start:=intPos, Length:=Len(varSearch)).Font.ColorIndex = 4
End If
Loop Until intPos = 0
End With
End If
Next I
End Sub
Note that if you indent the code correctly VBA
helps quite a lot. In your case, I have removed one Do
and I have added an End If
to make it work.
The easiest way to AutoIndent your code is to probably add SmartIndent or to do it here online - http://www.vbindent.com/
Edit - Something like this will allow you to loop through the worksheets:
Sub WorksheetLoop()
Dim WS_Count As Integer 'consider using Long instead of Integer somewhere in the future
Dim I As Integer
Dim varFound As Variant, varSearch As Variant
Dim strAddress As String, intPos As Integer
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
varSearch = "CUS_ECO_SEC_CD"
Set varFound = ws.Cells.Find(varSearch, LookIn:=xlValues, LookAt:=xlPart)
If Not varFound Is Nothing Then
strAddress = varFound.Address
With varFound
Do
intPos = InStr(intPos + 1, .Value, varSearch, vbTextCompare)
If intPos Then
.Characters(Start:=intPos, Length:=Len(varSearch)).Font.ColorIndex = 4
End If
Loop Until intPos = 0
End With
End If
Next ws
End Sub