The VBA Str Function

Related Function:
VBA Val

Description

The VBA Str function converts a supplied number into a string representation of that number.

The syntax of the function is:

Str( Number )

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:


VBA Str Function Examples

' Convert the numeric values +500 and -10.5 into strings.
Dim str1 As String
Dim str2 As String
str1 = Str( 500 )
' str1 is now equal to the String " 500".
str2 = Str( -10.5 )
' str2 is now equal to the String "-10.5".

Note that, in the above examples:


VBA Str Function Error

If the VBA Str function is supplied with a value that cannot be interpreted as a number, it will return the error:

Run-time error '13': Type mismatch

VBA Run Time Error 13 Message Box