Str Function Description
The VBA Str function converts a number into a string. It is equivalent to concatenating vbNullString with a number variable.
Syntax
The syntax for the Str function in VBA is:
1 | Str( number ) |
Parameters
number
The number to be convert into a string.
Other Notes
The resulting string will be preceded with a single whitespace character. Use LTrim to trim it if needed:
1 2 3 4 5 | Str 10 'Result: " 10" - leading whitespace LTrim Str(10) 'Result: "10" - no leading whitespace |
On a daily basis it is more convenient to simply concatenate vbNullString with our number to convert it to string format without a preceding whitespace character:
1 2 | vbNullString & 10" 'Result: "10" - no leading whitespace |
Example usage
The Str function can be used in VBA code. Let’s look at some VBA Str function examples:
1 2 3 4 5 | Str 10 'Result: " 10" Str 10.2 'Result: " 10.2" |