Created
February 1, 2017 00:04
-
-
Save larsschenk/d1650541ec39218556f9a56eb83ab720 to your computer and use it in GitHub Desktop.
Get variable type in VBA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Helper function | |
Private Function Get_Variable_Type(myVar) | |
If VarType(myVar) = vbNull Then | |
MsgBox "Null (no valid data) " | |
ElseIf VarType(myVar) = vbInteger Then | |
MsgBox "Integer " | |
ElseIf VarType(myVar) = vbLong Then | |
MsgBox "Long integer " | |
ElseIf VarType(myVar) = vbSingle Then | |
MsgBox "Single-precision floating-point number " | |
ElseIf VarType(myVar) = vbDouble Then | |
MsgBox "Double-precision floating-point number " | |
ElseIf VarType(myVar) = vbCurrency Then | |
MsgBox "Currency value " | |
ElseIf VarType(myVar) = vbDate Then | |
MsgBox "Date value " | |
ElseIf VarType(myVar) = vbString Then | |
MsgBox "String " | |
ElseIf VarType(myVar) = vbObject Then | |
MsgBox "Object " | |
ElseIf VarType(myVar) = vbError Then | |
MsgBox "Error value " | |
ElseIf VarType(myVar) = vbBoolean Then | |
MsgBox "Boolean value " | |
ElseIf VarType(myVar) = vbVariant Then | |
MsgBox "Variant (used only with arrays of variants) " | |
ElseIf VarType(myVar) = vbDataObject Then | |
MsgBox "A data access object " | |
ElseIf VarType(myVar) = vbDecimal Then | |
MsgBox "Decimal value " | |
ElseIf VarType(myVar) = vbByte Then | |
MsgBox "Byte value " | |
ElseIf VarType(myVar) = vbUserDefinedType Then | |
MsgBox "Variants that contain user-defined types " | |
ElseIf VarType(myVar) = vbArray Then | |
MsgBox "Array " | |
Else | |
MsgBox VarType(myVar) | |
End If | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment