Get the variable type for Variant : Variant « Data Type « VBA / Excel / Access / Word






Get the variable type for Variant

 

Sub VariantExample()
    Dim varAnyThing     As Variant
    varAnyThing = 12.345
    Debug.Print VarType(varAnyThing)
    
    varAnyThing = 12.345
    varAnyThing = varAnyThing & " is a number"
    Debug.Print VarType(varAnyThing)
    
    varAnyThing = 12.345
    varAnyThing = varAnyThing + "10"
    Debug.Print VarType(varAnyThing)
    
    varAnyThing = 12345
    Debug.Print VarType(varAnyThing)
    
    varAnyThing = 123456
    Debug.Print VarType(varAnyThing)

End Sub

 








Related examples in the same category

1.If you simply declare a variable with a Dim statement and leave off the type-declaration keyword or character, the variable is a variant
2.Variant string
3.A Variant allows VBA to make its own decision as to what type of data it is holding
4.One of the few instances in which you have no choice for using a Variant:
5.A Variant allows VBA to make its own decision as to what type of data it is holding: string and integer
6.Assign difference type variable to Variant variable
7.Add Variant integer to Variant string
8.Add Variant string to Variant integer
9.Add Variant integer in string to another Variant integer in string
10.Determining the Type of a Variant