How to use Space Function in Excel VBA?

Excel VBA provides the Space function that lets you to add spaces with-in your Excel spreadsheet in a intuitive way.

Assume that you need to add 5 spaces between two words Developer and Publish. You would usually do it by entering 5 spaces as shown below

Dim str1 As String

str1 = "Developer" & "     " & "Publish"

MsgBox str1

How to use Space Function in Excel VBA?

The same thing can be achieved using the Space() function in Excel VBA as shown below.

Dim str1 As String

str1 = "Developer" & Space(5) & "Publish"

MsgBox str1

The Space(5) inserts 5 spaces in the specified position.