Skip to main content
replaced https://web.archive.org/web/www.cpearson.com/ with http://www.cpearson.com/
Source Link
Public Sub CalculateMe(Optional varA As Variant, Optional varB as Variant) 

Excerpts from Chip Pearson'sChip Pearson's excellent explanation:

Rules governing the use of optional parameters:

  • The Optional keyword must be present to make a parameter optional.
  • The data type should be (but need not be, see below) a Variant data type.
  • The optional parameter(s) must be at the end of the parameter list.
  • The IsMissing function will work only with parameters declared as Variant. It will return False when used with any other data type.
  • User defined types (UTDs) cannot be optional parameters.

Example

Function Test(L1 As Long, L2 As Long, _ Optional P1 As Variant, Optional P2 As Variant) As String Dim S As String If IsMissing(P1) = True Then S = "P1 Is Missing." Else S = "P1 Is Present (P1 = " & CStr(P1) & ")" End If If IsMissing(P2) = True Then S = S & " " & "P2 Is Missing" Else S = S & " " & "P2 Is Present (P2 = " & CStr(P2) & ")" End If Test = S End Function 

Here, both L1 and L2 are required but P1 and P2 are optional. Since both are Variant types, we can use IsMissing to determine whether the parameter was passed in. IsMissing returns True if the Variant parameter is omitted, or False if the Variant parameter is included. If the data type of the optional parameter is any data type other than Variant, IsMissing will return False.

Public Sub CalculateMe(Optional varA As Variant, Optional varB as Variant) 

Excerpts from Chip Pearson's excellent explanation:

Rules governing the use of optional parameters:

  • The Optional keyword must be present to make a parameter optional.
  • The data type should be (but need not be, see below) a Variant data type.
  • The optional parameter(s) must be at the end of the parameter list.
  • The IsMissing function will work only with parameters declared as Variant. It will return False when used with any other data type.
  • User defined types (UTDs) cannot be optional parameters.

Example

Function Test(L1 As Long, L2 As Long, _ Optional P1 As Variant, Optional P2 As Variant) As String Dim S As String If IsMissing(P1) = True Then S = "P1 Is Missing." Else S = "P1 Is Present (P1 = " & CStr(P1) & ")" End If If IsMissing(P2) = True Then S = S & " " & "P2 Is Missing" Else S = S & " " & "P2 Is Present (P2 = " & CStr(P2) & ")" End If Test = S End Function 

Here, both L1 and L2 are required but P1 and P2 are optional. Since both are Variant types, we can use IsMissing to determine whether the parameter was passed in. IsMissing returns True if the Variant parameter is omitted, or False if the Variant parameter is included. If the data type of the optional parameter is any data type other than Variant, IsMissing will return False.

Public Sub CalculateMe(Optional varA As Variant, Optional varB as Variant) 

Excerpts from Chip Pearson's excellent explanation:

Rules governing the use of optional parameters:

  • The Optional keyword must be present to make a parameter optional.
  • The data type should be (but need not be, see below) a Variant data type.
  • The optional parameter(s) must be at the end of the parameter list.
  • The IsMissing function will work only with parameters declared as Variant. It will return False when used with any other data type.
  • User defined types (UTDs) cannot be optional parameters.

Example

Function Test(L1 As Long, L2 As Long, _ Optional P1 As Variant, Optional P2 As Variant) As String Dim S As String If IsMissing(P1) = True Then S = "P1 Is Missing." Else S = "P1 Is Present (P1 = " & CStr(P1) & ")" End If If IsMissing(P2) = True Then S = S & " " & "P2 Is Missing" Else S = S & " " & "P2 Is Present (P2 = " & CStr(P2) & ")" End If Test = S End Function 

Here, both L1 and L2 are required but P1 and P2 are optional. Since both are Variant types, we can use IsMissing to determine whether the parameter was passed in. IsMissing returns True if the Variant parameter is omitted, or False if the Variant parameter is included. If the data type of the optional parameter is any data type other than Variant, IsMissing will return False.

replaced http://www.cpearson.com/ with https://web.archive.org/web/www.cpearson.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot
Public Sub CalculateMe(Optional varA As Variant, Optional varB as Variant) 

Excerpts from Chip Pearson'sChip Pearson's excellent explanation:

Rules governing the use of optional parameters:

  • The Optional keyword must be present to make a parameter optional.
  • The data type should be (but need not be, see below) a Variant data type.
  • The optional parameter(s) must be at the end of the parameter list.
  • The IsMissing function will work only with parameters declared as Variant. It will return False when used with any other data type.
  • User defined types (UTDs) cannot be optional parameters.

Example

Function Test(L1 As Long, L2 As Long, _ Optional P1 As Variant, Optional P2 As Variant) As String Dim S As String If IsMissing(P1) = True Then S = "P1 Is Missing." Else S = "P1 Is Present (P1 = " & CStr(P1) & ")" End If If IsMissing(P2) = True Then S = S & " " & "P2 Is Missing" Else S = S & " " & "P2 Is Present (P2 = " & CStr(P2) & ")" End If Test = S End Function 

Here, both L1 and L2 are required but P1 and P2 are optional. Since both are Variant types, we can use IsMissing to determine whether the parameter was passed in. IsMissing returns True if the Variant parameter is omitted, or False if the Variant parameter is included. If the data type of the optional parameter is any data type other than Variant, IsMissing will return False.

Public Sub CalculateMe(Optional varA As Variant, Optional varB as Variant) 

Excerpts from Chip Pearson's excellent explanation:

Rules governing the use of optional parameters:

  • The Optional keyword must be present to make a parameter optional.
  • The data type should be (but need not be, see below) a Variant data type.
  • The optional parameter(s) must be at the end of the parameter list.
  • The IsMissing function will work only with parameters declared as Variant. It will return False when used with any other data type.
  • User defined types (UTDs) cannot be optional parameters.

Example

Function Test(L1 As Long, L2 As Long, _ Optional P1 As Variant, Optional P2 As Variant) As String Dim S As String If IsMissing(P1) = True Then S = "P1 Is Missing." Else S = "P1 Is Present (P1 = " & CStr(P1) & ")" End If If IsMissing(P2) = True Then S = S & " " & "P2 Is Missing" Else S = S & " " & "P2 Is Present (P2 = " & CStr(P2) & ")" End If Test = S End Function 

Here, both L1 and L2 are required but P1 and P2 are optional. Since both are Variant types, we can use IsMissing to determine whether the parameter was passed in. IsMissing returns True if the Variant parameter is omitted, or False if the Variant parameter is included. If the data type of the optional parameter is any data type other than Variant, IsMissing will return False.

Public Sub CalculateMe(Optional varA As Variant, Optional varB as Variant) 

Excerpts from Chip Pearson's excellent explanation:

Rules governing the use of optional parameters:

  • The Optional keyword must be present to make a parameter optional.
  • The data type should be (but need not be, see below) a Variant data type.
  • The optional parameter(s) must be at the end of the parameter list.
  • The IsMissing function will work only with parameters declared as Variant. It will return False when used with any other data type.
  • User defined types (UTDs) cannot be optional parameters.

Example

Function Test(L1 As Long, L2 As Long, _ Optional P1 As Variant, Optional P2 As Variant) As String Dim S As String If IsMissing(P1) = True Then S = "P1 Is Missing." Else S = "P1 Is Present (P1 = " & CStr(P1) & ")" End If If IsMissing(P2) = True Then S = S & " " & "P2 Is Missing" Else S = S & " " & "P2 Is Present (P2 = " & CStr(P2) & ")" End If Test = S End Function 

Here, both L1 and L2 are required but P1 and P2 are optional. Since both are Variant types, we can use IsMissing to determine whether the parameter was passed in. IsMissing returns True if the Variant parameter is omitted, or False if the Variant parameter is included. If the data type of the optional parameter is any data type other than Variant, IsMissing will return False.

deleted 11 characters in body
Source Link
Christopher Peisert
  • 24.5k
  • 4
  • 102
  • 127
Public Sub CalculateMe(Optional varA As Variant, Optional varB as Variant) 

Excerpts from Chip Pearson's excellent explanation:

There are a few rules that governRules governing the use of optional parameters:

  • The OptionalOptional keyword must be present to make a parameter optional.
  • The data type should be (but need not be, see below) a Variant data type.
  • The optional parameter(s) must be at the end of the parameter list.
  • The IsMissing function will work only with parameters declared as VariantVariant. It will return False when used with any other data type.
  • User defined types (UTDs) cannot be optional parameters.

Example

Function Test(L1 As Long, L2 As Long, _ Optional P1 As Variant, Optional P2 As Variant) As String Dim S As String If IsMissing(P1) = True Then S = "P1 Is Missing." Else S = "P1 Is Present (P1 = " & CStr(P1) & ")" End If If IsMissing(P2) = True Then S = S & " " & "P2 Is Missing" Else S = S & " " & "P2 Is Present (P2 = " & CStr(P2) & ")" End If Test = S End Function 

Here, both L1 and L2 are required but P1 and P2 are optional. Since both are Variant types, we can use IsMissing to determine whether the parameter was passed in. IsMissing returns True if the Variant parameter is omitted, or False if the Variant parameter is included. If the data type of the optional parameter is any data type other than Variant, IsMissing will return False.

Public Sub CalculateMe(Optional varA As Variant, Optional varB as Variant) 

Excerpts from Chip Pearson's excellent explanation:

There are a few rules that govern the use optional parameters:

  • The Optional keyword must be present to make a parameter optional.
  • The data type should be (but need not be, see below) a Variant data type.
  • The optional parameter(s) must be at the end of the parameter list.
  • The IsMissing function will work only with parameters declared as Variant. It will return False when used with any other data type.
  • User defined types (UTDs) cannot be optional parameters.

Example

Function Test(L1 As Long, L2 As Long, _ Optional P1 As Variant, Optional P2 As Variant) As String Dim S As String If IsMissing(P1) = True Then S = "P1 Is Missing." Else S = "P1 Is Present (P1 = " & CStr(P1) & ")" End If If IsMissing(P2) = True Then S = S & " " & "P2 Is Missing" Else S = S & " " & "P2 Is Present (P2 = " & CStr(P2) & ")" End If Test = S End Function 

Here, both L1 and L2 are required but P1 and P2 are optional. Since both are Variant types, we can use IsMissing to determine whether the parameter was passed in. IsMissing returns True if the Variant parameter is omitted, or False if the Variant parameter is included. If the data type of the optional parameter is any data type other than Variant, IsMissing will return False.

Public Sub CalculateMe(Optional varA As Variant, Optional varB as Variant) 

Excerpts from Chip Pearson's excellent explanation:

Rules governing the use of optional parameters:

  • The Optional keyword must be present to make a parameter optional.
  • The data type should be (but need not be, see below) a Variant data type.
  • The optional parameter(s) must be at the end of the parameter list.
  • The IsMissing function will work only with parameters declared as Variant. It will return False when used with any other data type.
  • User defined types (UTDs) cannot be optional parameters.

Example

Function Test(L1 As Long, L2 As Long, _ Optional P1 As Variant, Optional P2 As Variant) As String Dim S As String If IsMissing(P1) = True Then S = "P1 Is Missing." Else S = "P1 Is Present (P1 = " & CStr(P1) & ")" End If If IsMissing(P2) = True Then S = S & " " & "P2 Is Missing" Else S = S & " " & "P2 Is Present (P2 = " & CStr(P2) & ")" End If Test = S End Function 

Here, both L1 and L2 are required but P1 and P2 are optional. Since both are Variant types, we can use IsMissing to determine whether the parameter was passed in. IsMissing returns True if the Variant parameter is omitted, or False if the Variant parameter is included. If the data type of the optional parameter is any data type other than Variant, IsMissing will return False.

Source Link
Christopher Peisert
  • 24.5k
  • 4
  • 102
  • 127
Loading