F
Felixdecat
Hello, I have written the following code. The purpose is to find every
instance of a word in the worksheet, and then highlight it yellow. However,
it only finds the 1st instance, but does not carry on searching the rest of
the worksheet. Can anyone help me? The first part of the code clears the
previous search results.
Private Sub CommandButton1_Click()
Dim Wsht As Worksheet
Dim Rng As Range
Dim cl As Range
For Each Wsht In Worksheets
Set Rng = Wsht.UsedRange
For Each cl In Rng
With cl
If .Interior.ColorIndex = 6 Then
.Interior.ColorIndex = 0
End If
End With
Next cl
Next Wsht
Set Rng = Nothing
Set cl = Nothing
w = InputBox("Please enter a Word")
Cells.Find(What:=(w), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End Sub
instance of a word in the worksheet, and then highlight it yellow. However,
it only finds the 1st instance, but does not carry on searching the rest of
the worksheet. Can anyone help me? The first part of the code clears the
previous search results.
Private Sub CommandButton1_Click()
Dim Wsht As Worksheet
Dim Rng As Range
Dim cl As Range
For Each Wsht In Worksheets
Set Rng = Wsht.UsedRange
For Each cl In Rng
With cl
If .Interior.ColorIndex = 6 Then
.Interior.ColorIndex = 0
End If
End With
Next cl
Next Wsht
Set Rng = Nothing
Set cl = Nothing
w = InputBox("Please enter a Word")
Cells.Find(What:=(w), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End Sub