How do I exit a Do Loop when I get an error? I have a vba macro with a
do loop which searches a spreadsheet for the string "liquidat", selects
the row, cuts and pastes the row to a different worksheet, then goes
back to the original worksheet and searches for the string again.
Naturally, when it no longer finds the string, it generates the error
"Run-time error '91': Object variable or With block variable not set".
I tried "On Error Exit Do" but the compiler didn't like this. I tried
an ErrorHandler: Exit Do, but the compiler told me the Exit Do was
outside the loop. I tried "If Err.Number <> 0 Then Exit Do" before and
after the "Cells.Find(What:="liquidat"..." but of course this didn't
work because before the Find, Err.Number = 0, and once the error is
generated it never gets to the "If Err.Number <> 0 Then Exit Do" that
follows the error. (Incidently, how can "If Err.Number <> 0 Then Exit
Do" ever work?). So, I have been very busy but to no avail. Thanking
you now for any help.
Bookmarks