VBA CSTR Function (Syntax + Example)

- Written by Puneet

The VBA CSTR function is listed under the data type conversion category of VBA functions. When you use a VBA code, it converts an expression into the string data type. In simple words, with CSTR you can convert different types of values like boolean, Integer, or date into a string type value.

Syntax

CStr(Expression)

Arguments

  • Expression: The value which you want to convert to a string data type.

Example

To practically understand how to use the VBA CSTR function, you need to go through the below example where we have written a vba code by using it:

example-vba-cstr-function
Sub example_CSTR()
Range("B1").Value = CStr(Range("A1"))
End Sub

In the above example, we have used the value from cell A1 (1-Jan-19) and then we have used the COS to convert that value into a string data type and it has returned 1/1/2019 in the result.

Notes

  • If a date is specified as an expression it will return the text representation of the that as mm/dd/yyyy.