The VBA SPACE function is listed under the text category of VBA functions. When you use it in a VBA code, it returns a string which is consisting of a specified number of spaces. In simple words, with the space function, you can create spaces by supplying numbers.
- Number: A number to specify the number of spaces for making up the String in the result.
To practically understand how to use the VBA SPACE function, you need to go through the below example where we have written a vba code by using it:
Range("A1").Value = Space(5)
In the above code, we have used SPACE to create a string in cell B1 with the 5 spaces as we have specified 5 in the argument.
- If the number supplied is a negative number then VBA will return a run-time 5 error.