View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Michael[_21_] Michael[_21_] is offline
external usenet poster
 
Posts: 5
Default How do I change a function's otional parameter default values programmically

Vasant,

Thanks for the tip, the problem with the solution below is that the
two optional parameters values from the spreadsheet ALWAYS override
any data specifically passed into the function (c&d). I only want the
optional defaults to be used if NO DATA is passed into the optional
parameters of the function (c&d). For the two optional parameters,
one is type double, the other is type boolean, which doesn't allow me
to set the optional parameters to some recognizable dummy (to flag me
there was not a parameter passed so I can retrieve it from the
spreadsheat, for example, if the two optional parameters where
strings, I could set the optional default to "none passed", then use
an if-then statement to retrieve the defaults.)

Any more ideas?

~Michael


"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message ...
Hi Michael:

This seems to work for me (no error-checking provided):

Function SumFour(a As Integer, b As Integer, Optional c As Integer = 3, _
Optional d As Integer = 4)
If Range("A1") < "" And Range("A2") < "" Then
c = Range("A1")
d = Range("A2")
End If
SumFour = a + b + c + d
End Function

So if you have a UserForm to put values into the cells, those values will be
used as the optional parameters instead of your defaults.

Regards,

Vasant.