Space Function Description
The VBA Space function returns a string with the required number of whitespaces (” “).
Syntax
The syntax for the Space function in VBA is:
1 | Space( no_of_spaces ) |
Parameters
no_of_spaces
The number of whitespaces to be returned.
Other Notes
The VBA Space function replicates the following equivalent VBA Code:
1 2 3 4 5 6 7 | Function SpaceX(num As Long ) Dim i As Long , ret As String For i = 1 To num ret = ret & " " Next i SpaceX = ret End Function |
Example usage
The Space function can be used in VBA code. Let’s look at some VBA Space function examples:
1 2 3 4 5 | Space 4 'Result: " " Space 1 'Result: " " |