VBA CSTR Function

HomeVBA Functions LIST (Category Wise)How to use the VBA CSTR Function (Syntax + Example)

What is VBA CSTR Function

The VBA CSTR function is listed under the data type conversion category of VBA functions. When you use in 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.

how to use it

To use VBA's CSTR function you need to understand its syntax and arguments:

Syntax

CStr(Expression)

Arguments

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

Example to use CSTR Function in VBA

To practically understand how to use 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.

Notes

Below are some important points which you need to take care while using CSTR function in VBA.

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

About the Author

puneet one point one

Puneet is using Excel since his college days. He helped thousands of people to understand the power of the spreadsheets and learn Microsoft Excel. You can find him online, tweeting about Excel, on a running track, or sometimes hiking up a mountain.