Article ID: 165103 - Last Review: November 23, 2006 - Revision: 2.4 XL97: Value Returned by VarType for Omitted Arguments DiffersThis article was previously published under Q165103 SYMPTOMS
When you call a custom Visual Basic for Applications function from a
formula in a cell in a Microsoft Excel 97 worksheet, the VarType function
may return different values for missing optional arguments than it does in
earlier versions of Microsoft Excel. The IsMissing and IsNull functions may
also return different results.
CAUSE
This problem occurs because the method Microsoft Excel 97 uses to send
argument from worksheet formulas to Visual Basic for Applications functions
is different from the method used by earlier versions of Microsoft Excel.
NOTE: This problem does not occur when you use a Visual Basic for Applications subroutine to call a Visual Basic for Applications function. RESOLUTIONMicrosoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites: Microsoft Certified Partners - https://partner.microsoft.com/global/30000104 (https://partner.microsoft.com/global/30000104) Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice (http://support.microsoft.com/gp/advisoryservice) For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS (http://support.microsoft.com/default.aspx?scid=fh;en-us;cntactms) If the function uses the VarType, IsMissing, and/or IsNull functions to check the status of a missing argument, it may be necessary to modify the function to accommodate the change in behavior in Microsoft Excel 97. For example, if your function contains a line of code that is similar to the following You can use similar methods to correct any lines of code that uses the IsMissing and/or IsNull functions. STATUS
Microsoft has confirmed this to be a problem in the Microsoft products
listed at the beginning of this article.
This problem no longer occurs in Microsoft Excel 2000.
MORE INFORMATION
When you call a custom function from a formula in a worksheet cell, the
value that is returned by VarType for missing optional arguments differs
according to the version of Microsoft Excel that you are using. The values
that are returned by VarType for different versions of Microsoft Excel are
listed in the following table.
VarType Value for
Microsoft Excel Missing Arguments Corresponds to
-------------------------------------------------------------------
97 1 (vbNull) IsNull(<variable>) = True
IsMissing(<variable>) = False
5.0, 7.0 10 (vbError) IsMissing(<variable>) = True
IsNull(<variable>) = False
The following example demonstrates the change in behavior for the VarType function:
Cell Microsoft Excel 97 Microsoft Excel 5.0, 7.0 Different
---------------------------------------------------------------------
A1 IsMissing = False, False IsMissing = False, False No
IsNull = False, False IsNull = False, False No
VarType = 5, 5 VarType = 5, 5 No
A2 IsMissing = False, False IsMissing = True, False Yes
IsNull = True, False IsNull = False, False Yes
VarType = 1, 5 VarType = 10, 5 Yes
A3 IsMissing = False, False IsMissing = False, True Yes
IsNull = False, True IsNull = False, False Yes
VarType = 5, 1 VarType = 5, 10 Yes
A4 IsMissing = False, False IsMissing = True, True Yes
IsNull = True, True IsNull = False, False Yes
VarType = 1, 1 VarType = 10, 10 Yes
If you run the TestProc macro, the four message boxes that appear are identical in all versions of Microsoft Excel (5.0, 7.0, and Microsoft Excel 97). If you omit arguments when you call a Visual Basic for Applications function from a macro, the value returned by VarType for the missing arguments is always 10. | Article Translations
|

Back to the top
