VBA CVAR Function (Syntax + Example)

Last Updated: June 22, 2023
puneet-gogia-excel-champs

- Written by Puneet

The VBA CVAR function is listed under the data type conversion category of VBA functions. When you use it in a VBA code, it converts an expression into a variant data type. In simple words, a variant data type value can hold numeric, string, or date values. Learn more about variant data types from here.

Syntax

CVar(Expression)

Arguments

Expression: The value which you want to convert to a string data type.

Example

To practically understand how to use the VBA CVAR function, you need to go through the below example where we have written a vba code by using it:

example-vba-cvar-function
Sub example_CVAR()
Range("B1").Value = CVar(Range("A1"))
End Sub

In the above example, we have used the value from cell A1 (Excel Champs) and then we used the CVARvto convert that value into a variant data type and it has returned Excel Champs in the result.