First, the code would go in a general module (not behind the worksheet).
Then rename it to something that's memorable (not testme!).
And you could limit your range by looking just within the used range.
Option Explicit
Sub testme()
Dim myColorIndex As Long
Dim myCell As Range
Dim myRng As Range
Set myRng = Nothing
On Error Resume Next
With ActiveSheet 'or with worksheets("sheet1")
Set myRng = Intersect(.Range("o5:Iv2232"), .UsedRange)
End With
If myRng Is Nothing Then
Exit Sub
End If
For Each myCell In myRng.Cells
Select Case LCase(myCell.Value)
Case Is = "b": myColorIndex = 3
Case Is = "v": myColorIndex = 5
Case Else: myColorIndex = xlNone
End Select
myCell.Interior.ColorIndex = myColorIndex
Next myCell
End Sub
By using the "with activesheet", you can run it against any worksheet.
By using the "with worksheets("sheet1"), it only runs against sheet1, but you
can run the macro from any worksheet in that workbook.
In fact, it might be quicker to just seach for the values and fix them (rather
than looping through the whole range):
Option Explicit
Sub testme()
Dim FirstAddress As String
Dim FoundCell As Range
Dim FindWhatList As Variant
Dim myColorList As Variant
Dim iCtr As Long
Dim myRng As Range
Dim myOrigRng As Range
FindWhatList = Array("b", "v")
myColorList = Array(3, 5)
If UBound(FindWhatList) <> UBound(myColorList) Then
MsgBox "design error!"
Exit Sub
End If
With ActiveSheet
Set myOrigRng = .Range("o5:iv2232")
myOrigRng.Interior.ColorIndex = xlNone
Set myRng = Nothing
On Error Resume Next
Set myRng = Intersect(myOrigRng, .UsedRange)
On Error GoTo 0
End With
If myRng Is Nothing Then
Exit Sub
End If
For iCtr = LBound(FindWhatList) To UBound(FindWhatList)
FirstAddress = ""
With myRng
Set FoundCell = .Cells.Find(what:=FindWhatList(iCtr), _
LookIn:=xlValues, lookat:=xlWhole, _
searchdirection:=xlNext, _
after:=.Cells(.Cells.Count))
If Not FoundCell Is Nothing Then
FirstAddress = FoundCell.Address
Do
FoundCell.Interior.ColorIndex = myColorList(iCtr)
Set FoundCell = .FindNext(FoundCell)
Loop While Not FoundCell Is Nothing _
And FoundCell.Address <> FirstAddress
End If
End With
Next iCtr
End Sub