Excel VarType Function: Evaluate Excel Variable Types | Excel Help
Your Programming and Traning Professionals

Excel VarType Function: Evaluate Excel Variable Types


The Excel VarType function is a great function to use to evaluate what the type of variable you are working with.

The Basics:

The VarType function returns a variant, which contains the reference to what type of variable data you have been working with. The reference is represented by a value which you can interpret.

So let’s take look at an example. The example is simple, however when you are working with a significant project there might be instances were you want to evaluate the type of data you are working with.

Code

Dim StringToProcess As String’The variable that will contain the string to be evaluated

Dim AnotherValue As Variant

StringToProcess = “Excel is a great tool”

AnotherValue = “Excel is a great tool”

MsgBox (“The variable type for the variable StringToProcess is ” & VarType(StringToProcess))

MsgBox (“The variable type for the variable AnotherValue is ” & VarType(StringToProcess))

Output

The Variant variable can become any variable type. Because the variant contains a string value it will return 8 which is the vartype for a string.