How to use the VBA CVAR Function (Syntax + Example)

HomeVBA Functions LIST (Category Wise)How to use the VBA CVAR Function (Syntax + Example)

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 type 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 VBA CVAR function, you need to go through the below example where we have written a vba code by using it:

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 have used the CVARvto convert that value into a variant data type and it has returned Excel Champs in the result.

Related Functions

CBOOL | CBYTE | CCUR | CDATE | CDBL | CDEC | CHR | CINT | CLNG | CSNG | CSTR | FORMATCURRENCY | FORMATDATETIME | FORMATNUMBER | FORMATPERCENT | HEX | OCT | STR | VAL