> ## Content Index
> Fetch the complete content index at: https://nolongerset.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# VarType in VBA
- URL: https://nolongerset.com/vartype-in-vba/
- Published: 2021-05-14T03:06:03.000Z
- Updated: 2026-05-08T13:04:42.000Z
- Description: The VarType function lets you determine the underlying type of a variable. How does it fit in with TypeName and TypeOf?
- Author: Mike Wolfe
- Tags: Advanced, #Import 2026-05-20 02:59

In my article *[TypeName vs. TypeOf](https://nolongerset.com/typeof-vs-typename/)*, I wrote that I use TypeName when dealing with value types (like String, Integer, etc.) because TypeOf...Is expressions only work with object types. 

After I posted the article, Mathieu Guindon (aka, [@rubberduckvba](https://twitter.com/rubberduckvba)) pointed out on Twitter that there is a third alternative to TypeName and TypeOf...Is expressions–the [VarType function](https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/vartype-function).

> What about VarType? Usually better option than the stringly-typed TypeName way 😊
> 
> — Rubberduck VBIDE add-in (@rubberduckvba) [May 13, 2021](https://twitter.com/rubberduckvba/status/1392694672112377859?ref%5Fsrc=twsrc%5Etfw)

## VarType vs. TypeName

Mathieu's point–and it's a good one–is that we should always prefer solutions that provide compile-time checks over those that do not. 

What does that even mean? Why should we care? I think a quick example is in order.

In the sample code below, I'm checking the underlying type of a Variant argument being passed to my function. Everything works as you would expect until the last line of my subroutine where I misspelled "String" as "Stirng". But, since the misspelling occurred within a string literal, the compiler saw no problem:

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/05/image-39.png)

However, if I were to make a similar typo in my VarType comparison, the code won't even compile:

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/05/image-40.png)

## Compile errors are good!

Because they're easy to catch and easy to fix.

Compile-time checks almost always get caught in development (so long as you remember to regularly compile your code: Debug > Compile). 

Meanwhile, typos in string literals are easily missed. 

And if you miss a typo in a string literal, the *best case* scenario is you end up with a runtime error. The *worst case* scenario is you end up with a logic error that goes unnoticed, silently wreaking havoc with its second- and third-order side effects (such as inconsistent data, invalid program state, etc.).

### Revised Rule of Thumb

Use the first item in the following list that you can make work for the situation at hand:

- TypeOf...Is expression
- VarType function
- TypeName function

*Image by [Jondolar Schnurr](https://pixabay.com/users/shawshank66-1931526/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=1218884) from [Pixabay](https://pixabay.com/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=1218884)*