Referring to Variants
You can assign a Variant variable a value of any of the scalar data types where assigning a value of one scalar data type to a variable of another scalar data type would produce an error, as in the following example:
Dim myVariantV As Variant
Dim myVariantArrayV(1 to 5) As Variant
Dim aString As String
Dim anInt As Integer
myVariantV = 1234567
myVariantArrayV(1) = 1234567
myVariantV = "Hello"
myVariantArrayV(1) = myVariantV
aString$ = 1234567
' Produce an error, because 1234567 is not a String.
anInt% = 1234567
' Produce an error because 1234567 is too large
' to be treated as an Integer.
The Variant data type allows you a great deal of freedom in manipulating values of different types (such as dates) without having to concern yourself with type checking and compatibility issues. The Variant data type also makes it possible for arrays and lists to hold items of different data types (rather than being restricted to a single type) and significantly expands the range of data that you can include in a user-defined data type. However, Variants take up more storage than scalars, and operations involving Variants tend to be slower than those involving scalars. It is easy to lose track of the specific data type of a value that you are manipulating, which can sometimes produce unexpected results. Consider whether you really need to use a Variant variable, rather than a variable of one of the explicitly declared scalar types, to perform a given operation with efficiency.