user2989981
user2989981

Reputation: 89

Calling a sub, except for a few lines

Is it possible to call a sub and have the sub run with the exception of a few lines within the sub that is being called?

So for example, I want to call a "master_clear" sub from my "main" sub, but I do not want the master_clear to clear everything; there are some ranges that need to be left. How can I do this?

Upvotes: 0

Views: 76

Answers (1)

RubberDuck
RubberDuck

Reputation: 12748

You can use an optional parameter.

Sub foo(someParam as String, Optional doExtra as Boolean = False)
   'Do stuff

   If doExtra Then
       'Do extra stuff
   End If

   'Do some more stuff
 End Sub

Sub bar
    foo "hello" ' skip extra stuff
    foo "bye", True ' do extra stuff
End Sub

More on Optional parameters

Upvotes: 3

Related Questions