Article ID: 165103
Article Last Modified on 11/23/2006
If VarType(X) = 10 Thenchange the line so that it accounts for a VarType of 1 (the default) in Microsoft Excel 97, for example:
If (VarType(X) = 10 And Application.Version < 8) Or (VarType(X) = 1 _
And Application.Version = 8) Then
This line of code accounts for the difference in behavior between Microsoft
Excel 97 and earlier versions of Microsoft Excel.
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
NOTE: This difference does NOT apply when you use a Visual Basic for
Applications subroutine to call a custom function. If you omit arguments
when you use a Visual Basic for Applications subroutine to call a custom
function, the value that is returned by VarType for the missing arguments
is 10 in all versions of Microsoft Excel (versions 5.0, 7.0, and Microsoft
Excel 97).
Function TestIsMissing(Optional A, Optional B)
TestIsMissing = "IsMissing = " & IsMissing(A) & ", " & _
IsMissing(B) & Chr(10) & "IsNull = " & IsNull(A) & ", " & _
IsNull(B) & Chr(10) & "VarType = " & VarType(A) & ", " & _
VarType(B)
End Function
Sub TestProc()
MsgBox TestIsMissing(A:=1, B:=2)
MsgBox TestIsMissing(B:=2)
MsgBox TestIsMissing(A:=1)
MsgBox TestIsMissing
End Sub
A1: =TestIsMissing(1,2)
A2: =TestIsMissing(,2)
A3: =TestIsMissing(1,)
A4: =TestIsMissing(,)
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
Microsoft Excel 97 reports missing arguments as null values because the
value that is returned by VarType for these arguments is 1. In earlier
versions of Microsoft Excel, the missing arguments are reported as error
values because the value that is returned by VarType is 10.
Additional query words: 97 XL97 xlvbmigrate
Keywords: kbhowto kbprogramming KB165103