VBA STR Function (Syntax + Example)

Last Updated: June 22, 2023
puneet-gogia-excel-champs

- Written by Puneet

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.

Syntax

Str(Number)

Arguments

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

Example

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:

example-vba-str-function
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.

Notes

  • 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.