I want to highlight all accuring values in a excel file. My code however only highlights the first found value for every sheet, but I want to highlight every found value. I guess the ``FindNext'' does not work as i expect it to work. I tried multple other examples from the internet, which show the same result. What is going wrong?
Sub test()
Dim counter As Integer
Dim currentSheet As Integer
Dim cell As Range
On Error Resume Next
currentSheet = ActiveSheet.Index
datatoFind = StrConv(InputBox("Please enter the value to search for"), vbLowerCase)
If datatoFind = "" Then Exit Sub
sheetCount = ActiveWorkbook.Sheets.Count
If IsError(CDbl(datatoFind)) = False Then datatoFind = CDbl(datatoFind)
For counter = 1 To sheetCount
Sheets(counter).Activate
Set cell = Cells.Find(What:=datatoFind, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)
If Not cell Is Nothing Then
FirstAddress = cell.Address
Do
cell.Interior.Color = RGB(255, 0, 0)
cell = Cells.FindNext(After:=cell)
Loop Until cell.Address = FirstAddress
End If
Next counter
End Sub