VBA CStr function

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

CStr Function Description

The CStr function converts any variable to a string variable.

Syntax

The syntax for the CStr function in VBA is:

CStr( expression )

Parameters

value
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.:

CStr 21123
'Result: "21123" (String)

"" & 21123
'Result: "21123" (String)

Example usage

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

CStr 12345
'Result: "12345" (String)

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

Simply the best place to learn VBA!

Error: Please enter a valid email address

Error: Invalid email

Error: Please enter your first name

Error: Please enter your last name

Error: Please enter a username

Error: Please enter a password

Error: Please confirm your password

Error: Password and password confirmation do not match