hello I try to find all occurrences of "spare" inside a certain range in all shapes and forms "xxspareyy" should also be returned, i believe lookat:=xlPart takes care of that? but i dont get any results. not even if the cell value is "spare"
here is the code lr1 is last row and lc1 is last column
I think I'm missing something stupid here but cant find it
Thanks
here is the code lr1 is last row and lc1 is last column
Code:
needle = "spare"
spares = 0
With Range(Cells(10, 1), Cells(lr1, lc1))
Set lastcell = .Cells(.Cells.count)
End With
Set foundcell = Range(Cells(10, 1), Cells(lr1, lc1)).Find(What:=needle, after:=lastcell, LookAt:=xlPart, MatchCase:=False)
If Not foundcell Is Nothing Then
FirstAddr = foundcell.Address
spares = spares + 1
End If
Do Until foundcell Is Nothing
Debug.Print foundcell.Address
Set foundcell = Range(Cells(10, 1), Cells(lr1, lc1)).FindNext(after:=foundcell)
If foundcell.Address = FirstAddr Then
Exit Do
End If
spares = spares + 1
Loop
MsgBox spares & " #spares"
I think I'm missing something stupid here but cant find it
Thanks