The VBA Str function converts a supplied number into a string representation of that number.
The syntax of the function is:
Where the Number argument is the number that you want to convert into a string.
Note: the Str function always reserves the first character of the returned string for the sign of the supplied Number. Therefore:
' Convert the numeric values +500 and -10.5 into strings.
Dim str1 As String
Dim str2 As String
str1 = Str( 500 )
str2 = Str( -10.5 )' str1 is now equal to the String " 500". ' str2 is now equal to the String "-10.5". |
Note that, in the above examples:
If the VBA Str function is supplied with a value that cannot be interpreted as a number, it will return the error: