Multiple Optionals in A Procedure Header

MikeG

Well-known Member
Joined
Jul 4, 2004
Messages
845
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have the following code:

Sub(Optional Answer="Yes")

Could someone tell me the format for adding another variable as optional?

Thanks,

MikeG
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi Mike

Maybe something like this

Code:
Sub aTest(Optional answer As String = "Yes", Optional name As String = "Peter")
    
    If answer = "Yes" Then
        MsgBox name & " answered the question"
    Else
        MsgBox name & " has not answered the question"
    End If
    
    
End Sub

Sub bTest()
    Call aTest(, "John")
    Call aTest("Yes")
    Call aTest("No", "John")
    Call aTest
End Sub

M.
 
Upvote 0
Hi Mike

Maybe something like this

Code:
Sub aTest(Optional answer As String = "Yes", Optional name As String = "Peter")
    
    If answer = "Yes" Then
        MsgBox name & " answered the question"
    Else
        MsgBox name & " has not answered the question"
    End If
    
    
End Sub

Sub bTest()
    Call aTest(, "John")
    Call aTest("Yes")
    Call aTest("No", "John")
    Call aTest
End Sub

M.

Thanks very much,

Mike
 
Upvote 0

Forum statistics

Threads
1,214,968
Messages
6,122,509
Members
449,089
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top