VBA CStr function

CStr Function Description

The CStr function converts any variable (number, boolean etc.) to a string variable. This functions achieves a similar result as adding the variable to an empty String (vbNullString).


The syntax for the CStr function in VBA is:

CStr( expression )


An expression / variable that is to be converted to String data type.

Other Notes

The CStr function can be superseded by a simple string concatenation e.g.:

Debug.Print CStr(21123)
'Result: "21123" (String)

'Is similar to:

Debug.Print ("" & 21123)
'Result: "21123" (String)

'Or even better:
Debug.Print (vbNullString & 21123)
'Result: "21123" (String)

As you can read here it is recommended to use the vbNullString variable instead of an empty string ” “ for heavy VBA calculations.

Example usage

The CStr function can only be used in VBA code. Let’s look at some CStr function examples:

Debug.Print CStr(12345)
'Result: "12345" (String)

Dim tmp as Long
tmp = 10
Debug.Print CStr( tmp )
'Result: "10" (String)