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

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
 
R

Ron Rosenfeld

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
 
K

ker_01

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top