Goal: Search B14:C18 for "Global Outperformance Details", if found, put border around B14:C16, if not found, go to next sht (continue loop). The Find statement is working perfectly (i've debug.printed it to test on individual sheets) but I just can't figure out how to properly skip to next sheet if the find is nothing.
Issue: I am getting a '91' error (Object or with variable not defined) on FindGlOutperfDet =
which I know occurs when the Find results in nothing. I have tested the code on individual sheets (without the for each loop)and it works put the border in place when the text is found and throws the same error when it is not found.
I have worked through the below pages but still get the error.
how to detect whether VBA excel found something?
IF FIND function doesn't find anything in vba then
Attempt 1:
Sub Findtext()
Dim FindGlOutperfDet As Long
Dim Sht As Worksheet
For Each Sht In Worksheets
FindGlOutperfDet = Sht.Range("B14:C18").Find(What:="Global Outperformance Details", After:=Range("B18"), LookAt:=xlPart, LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row
If Not IsError(FindGlOutperfDet) Then
Sht.Range("B14:C16").BorderAround ColorIndex:=1, Weight:=xlMedium
End If
Next Sht
End Sub
Attempt 2:
Sub FindSomeCells123()
Dim FindGlOutperfDet As Range
Dim Sht As Worksheet
For Each Sht In Worksheets
FindGlOutperfDet = Sht.Range("B14:C18").Find(What:="Global Outperformance Details", After:=Range("B18"), LookAt:=xlPart, LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False)
If Not FindGlOutperfDet Is Nothing Then
Sht.Range("B14:C16").BorderAround ColorIndex:=1, Weight:=xlMedium
End If
Next Sht
End Sub