Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
optional args in UDF
Hi
How can I add optional arguments to a UDF? Function myfunc(arg1,arg2,[arg3]) -that with theses squared brackets doesn't work... thanks for help masterphilch |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
optional args in UDF
Give this a try. I have assigned a default value to the optional argument (if
one is not supplied)... Public Function MyFunction(ByVal Arg1 As String, _ ByVal Arg2 As String, _ Optional ByVal Arg3 As String = "Tada") MyFunction = Arg1 & Arg2 & Arg3 End Function -- HTH... Jim Thomlinson "masterphilch" wrote: Hi How can I add optional arguments to a UDF? Function myfunc(arg1,arg2,[arg3]) -that with theses squared brackets doesn't work... thanks for help masterphilch |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
optional args in UDF
You're looking at thge definition syntax, not how code is written.
Function myfunc(arg1, arg2, Optional arg3) If IsMissing arg3 Then 'do something End If ..... -- HTH Bob Phillips (remove nothere from email address if mailing direct) "masterphilch" wrote in message ... Hi How can I add optional arguments to a UDF? Function myfunc(arg1,arg2,[arg3]) -that with theses squared brackets doesn't work... thanks for help masterphilch |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
optional args in UDF
Use the word Optional.
Function MyFunction(X As Long, Y As Long, Optional Z As Long) Optional arguments must be the last arguments in the list. You can also provide a default value for the argument, to be used if the argument is omitted. E.g, Function MyFunction(X As Long, Y As Long, Optional Z As Long = 123) If you declare the optional argument As Variant, you can use IsMissing to determine whether the argument was supplied. E.g., Function MyFunction(X As Long, Y As Long, Optional Z As Variant) If IsMissing(Z) = True Then Debug.Print "Z is missing" End If End Function -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "masterphilch" wrote in message ... Hi How can I add optional arguments to a UDF? Function myfunc(arg1,arg2,[arg3]) -that with theses squared brackets doesn't work... thanks for help masterphilch |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
optional args in UDF
Chip Pearson schrieb:
Use the word Optional. Function MyFunction(X As Long, Y As Long, Optional Z As Long) Optional arguments must be the last arguments in the list. You can also provide a default value for the argument, to be used if the argument is omitted. E.g, Function MyFunction(X As Long, Y As Long, Optional Z As Long = 123) If you declare the optional argument As Variant, you can use IsMissing to determine whether the argument was supplied. E.g., Function MyFunction(X As Long, Y As Long, Optional Z As Variant) If IsMissing(Z) = True Then Debug.Print "Z is missing" End If End Function thanks for all replies! I just didn't think, that vba is a language including words like 'Optional'. thanks! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
optional calculations | Excel Worksheet Functions | |||
Optional hyphen? | Excel Discussion (Misc queries) | |||
Optional Linking | Excel Discussion (Misc queries) | |||
Application.Run("MacroName", Args) | Excel Programming | |||
Over 29 args in a UDF with double parens | Excel Programming |