I'm adding functionality to a report where some columns will be output with a cell containing 'Delete Me'.
I'm looking to loop a find function in the macro to find 'Delete Me', then delete the entire column.
At the moment, there will be a maximum of three instances of 'Delete Me', so I'm looping three times.
When there are three instances of 'Delete Me', the below Sub works fine, but when there are fewer than three, I get an error message: "Run-time error '91': Object variable or With block variable not set"
Sub Test()
Dim i As Integer
For i = 1 to 3
Cells.Find(What:="Delete Me", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Selection.EntireColumn.Delete
Next i
End Sub
What I'd like to do is loop until the find function doesn't find a 'Delete Me', then exit the Sub.