CVar VBA Function – How to Convert Data to Variant

Last Updated on January 11, 2023 by token

1. CVar VBA function – Description

The CVar VBA function   returns a value with the Variant data type  . The Variant data type can store both numeric and text data. When using this function, remember that the Variant data type itself is the least efficient data type in VBA.

2. VBA CVar Function – Syntax

CVar (Expression) as Variant

Expression : Any value stored in any data type.

Function return : Variant / Any numerical or text value.

3. VBA CVar function – Example

How to use CVar function in VBA Excel? Below are examples of using the CVar function in the VisualBasic Editor.

Example 1: Converting to Variant. CVar – function example. The result in the MsgBox window.

Dim varValue As Variant
varValue = CVar ("any value")
MsgBox varValue

Example 1: Converting to Variant. VBA CVar – example. The result in the worksheet cells.

Dim varValue As Variant
varValue = CVar (123)
Range ("A1") = varValue

4. VB CVar function – Additional information

  • none

5. CVar VisualBasic function – Where to use?

The function can be used in: Excel 2003, Excel 2007, Excel 2010, Excel 2013, Excel 2016, Excel 2019, Excel 2021, Excel 365.

The article is part of the VBA Excel function list. You can find a list of all VBA functions at this address:  VBA functions .

Leave a comment

Your email address will not be published. Required fields are marked *

%d bloggers like this: