VBA STR Function (Syntax + Example)


- Written by Puneet (Last Updated: June 22, 2023)

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.




  • Number: A number that you want to convert into a string.


To practically understand how to use the 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 cell A1 into a string and return the result in cell B1.


  • 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.
Last Updated: June 22, 2023