The VBA Space function creates a String consisting of a specified number of spaces.
The syntax of the function is:
Where the Number argument is the number of spaces making up the returned String.
' Example 1 - Create a String containing 5 spaces.
' Example 2 - Create a String containing 0 spaces.Dim str1 As String str1 = Space( 5 ) ' The variable str1 is now equal to " " (five spaces). Dim str2 As String str2 = Space( 0 ) ' The variable str2 is now equal to "" (an empty string). |
In the above example:
If you supply a negative Number argument to the VBA Space function, you will get the error:
If the Number that is supplied to the Space function is a text string that cannot be converted into a numeric value, you will get the error: