Optional Argument anomaly?
Your code doesn't seem to be complete; there are unfinished Ifs.
If you want to test for an omitted B, use the IsMissing() function.
--
Kind regards,
Niek Otten
Microsoft MVP - Excel
"mickey" wrote in message ...
| Have run across a problem with an optional variant.
|
| Code Example:
|
| Function X (A As Range, Optional B As Variant = ?) As Variant
|
| If IsEmpty(B) Then MsgBox "B is Empty"
| If IsNull(B) Then MsgBox "B is Null"
| If IsError(B) Then MsgBox "B is Error"
|
| If the optional argument "B" is initialized to "Null" (i.e. Optional B As
| Variant = Null) then the message "B is Null" is displayed. However, if "B"
| is initialized to "Empty" (i.e. Optional B As Variant = Empty), the "IsEmpty"
| is false and the message "B is Error" is displayed.
|
| Does anyone know why the initialization of "B" to "Empty" results in an error?
|
| Thanks.
|