Function Declarations !!!!!!!!!!!!!!!!!!!!!!

  • Thread starter Thread starter Ayo
  • Start date Start date
A

Ayo

How do you declare a variable as OPTIONAL in a UDF. I have a function that I
use in one of my macros but I would like to declare at least one of the
variables as an optional variable. I am not sure how to do that.
Any ideas?

Thanks
Ayo
 
How do you declare a variable as OPTIONAL in a UDF. I have a function that I
use in one of my macros but I would like to declare at least one of the
variables as an optional variable. I am not sure how to do that.
Any ideas?

Thanks
Ayo

Look at VBA Help for the Optional keyword. Here's an example, but there are
restrictions on its use you should be familiar with.

Function foo(s As String, n As Long, Optional o As Variant, _
Optional m As String = "bar") As String
....
....
End Function
--ron
 
The key thing to remember is that every variable you declare after the first
optional parameter will also be optional (you cannot have required, then
optional, then required)

Here is a real one from one of my workbooks:
Function PullAllRawData(SourceSheet As Worksheet, _
DestSheet As Worksheet, _
Optional PathOnly As String, _
Optional MyFullFilePath As String, _
Optional TitleString As String)

In this case, it isn't a UDF, but I'd expect it should work the same way.

HTH,
Keith
 
Back
Top