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:
- 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.
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 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 ﬁnd him online, tweeting about Excel, on a running track, or sometimes hiking up a mountain.