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 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 VBA SPACE function, you need to go through the below example where we have written a vba code by using it:
Sub example_SPACE() Range("A1").Value = Space(5) End Sub
In the above code, we have used the SPACE to create a string in the 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.