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.

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this article, you will learn about the SKEW.P function, the formula syntax and usage of the function in Microsoft...
In this article, you will learn about the SKEW function, the formula syntax and usage of the function in Microsoft...
In this article, you will learn about the RANK.EQ function, the formula syntax and usage of the function in Microsoft...
  • Excel
  • November 23, 2021