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.
- Expression: The value which you want to convert to a string data type.
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:
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.
- If a date is specified as an expression it will return the text representation of the that as mm/dd/yyyy.