Stopping a Macro without an end sub


Posted by Pol on February 21, 2001 11:59 AM

I have recorded a macro which searchs for a certain field then add data into other sheets etc but i want it to stop if it does not find this field and not continue with the rest of the macro. An End sub command doesnt work as it stops the rest of the macro from working away

Posted by greg on February 21, 2001 1:49 PM

Make an if statement and if the statement is false put exit sub, this will exit the the sub and the macro will stop running only if the statement is false.

Posted by David Hawley on February 21, 2001 11:01 PM


Hi Pol

Sub TryThis()
Dim FoundCell As Range
On Error Resume Next
Set Found = Columns(1).Find(What:="Dog", After:=[A1])
If Found Is Nothing Then Exit Sub

'Code to continue

End Sub

Dave


OzGrid Business Applications



Posted by Mallow on February 23, 2001 6:29 AM

Wow! What a great answer!