VbaObjectsIntermediate

Variant type

Stores different kinds of data and is the default fallback type in VBA.

Review the syntaxStudy the examplesOpen the coding app
Dim value As Variant

This static page keeps the syntax and examples indexed for search, while the coding app handles interactive exploration and saved references.

What it does

Overview

Stores different kinds of data and is the default fallback type in VBA.

Variant is flexible and convenient for Excel automation because worksheet values can be empty, numeric, textual, dates, or arrays. That flexibility is helpful for quick macros and range transfers, but it also hides coercion bugs and makes debugging harder when you really needed a more specific type.

Quick reference

Syntax

Dim value As Variant

See it in practice

Examples

1

Read mixed worksheet values

Dim cellValue As Variant
cellValue = Range("A2").Value
If IsEmpty(cellValue) Then MsgBox "Blank cell"

Variant handles unpredictable worksheet data more safely than forcing one narrow type too early.

Debug faster

Common Errors

1

LogicError

Cause: Letting silent type coercion hide text-number or date conversion problems.

Fix: Validate the value with IsNumeric, IsDate, VarType, or convert explicitly before arithmetic.

Runtime support

Compatibility

Excel desktop VBA

Source: Microsoft Learn Office VBA reference

Common questions

Frequently Asked Questions

Stores different kinds of data and is the default fallback type in VBA.

LogicError: Validate the value with IsNumeric, IsDate, VarType, or convert explicitly before arithmetic.