What is VBA STR Function
The VBA STR function is listed under the data type conversion category of VBA functions. When you use it in VBA code, it converts a number into a string. In simple words, it can convert a number into a text which represents the number.
how to use it
To use VBA's STR function you need to understand its syntax and arguments:
- Number: A number for which you want to convert into a string.
Example to use STR Function in VBA
To practically understand how to use VBA STR function, you need to go through the below example where we have written a vba code by using it:
Sub example_STR() Range("B1").Value = Str(Range("A1")) End Sub
In the above code, we have used the STR to convert the numeric value in the cell A1 into a string and return the result in the cell B1.
Below are some important points which you need to take care while using STR function in VBA.
- It adds a leading space every time it converts a number to a string for the sign of the number.
- If the value specified is a value other than a number or a number that can’t be recognized as a number, VBA will return the run-time 13 error.
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.