Learn Excel - Simplify Life with Excel Concepts

Excel CVar Function (VBA)

CVar Function VBA Code

How to use the CVar Function (VBA)

This Excel tutorial explains how to use the Excel CVar function with syntax and examples using VBA.

SUMMARY:

The Excel VBA CVar function converts an expression into a Variant data type.

For example,

  • The VBA Code CVar("Hello") would return "Hello"
  • The VBA Code CVar(33.955555) would return 33.955555

PURPOSE:

To converts a value to a Variant.

RETURN VALUE:

The CVar function returns a Variant value.

SYNTAX:

CVar( expression )

ARGUMENTS:

The CVar function syntax has the following arguments:

  • expression: Required. The expression is that you want to convert to a Variant data value.
    • The "expression" can be the same range as a double for numeric expression.
    • The "expression" can be the same range as a string for non-numeric expressions.
    • If "expression" is outside the range of the data type being converted to, an error occurs.

REMARKS:

  • The CVar function can only be used in VBA code in Microsoft Excel.
  • The CVar Function can convert different types of expression (Integer, Boolean and Date) into String data types.
  • The CVar function can be used to convert numeric values, strings and dates into Variant data types.
  • The Variant data type can hold numeric, string, or date values.
  • VBAs hexadecimal notation symbol is "&H"

Useful Links: Link 1Link 2Link 3Link 4