VBA Str function

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Str Function Description

The VBA Str function converts a number into a string. It is equivalent to concatenating vbNullString with a number variable.


The syntax for the Str function in VBA is:

Str( 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:

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:

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:

Str 10
'Result: " 10"

Str 10.2
'Result: " 10.2"

Simply the best place to learn Excel VBA