CStr VBA function – How to convert data to string type

1. CStr VBA function – Description

The CStr VBA function   returns a value of the String data type  . The simplest form of the String data type with a variable number of characters takes up as many bytes in memory as there are characters in a given text string. We typically use functions when converting text stored in Variant to more efficient data types.

2. VBA CStr function – Syntax

CStr (Expression) As String

Expression : Any value.

Function return : String / text value.

3. VBA CStr function – Example

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

Example 1: Converting to a String type. CStr – VBA function example. The result in the MsgBox window.

Dim varValue As Variant
varValue = "any text"
MsgBox CStr (varValue)

Example 2: Converting to a String type. VBA CStr – function example. The result in a sheet cell.

Dim varValue As Variant
varValue = "any text"
Range ("A1") = CStr (varValue)
Excel VBA functions - CStr VBA function
Excel VBA functions – CStr VBA function

4. VB CStr function – Additional information

  • lack

5. CStr VisualBasic function – Where to use?

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

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: