VBA Space Function – Add Spaces to a String

Associated Files Download Links


Add Spaces to a String

A common way to add spaces to a string with VBA is to use blank spaces between quotation marks. The following example adds ten spaces between the word “Hello” and “World”:

VBA Space Function

A more intuitive way to add spaces to a string is to use the Space() function. The following does the same as the previous code, however it uses the Space() function:

Sidenote: This works in VBA, however it doesn’t work in a spreadsheet formula. Instead use the REPT Function to repeat a character, such as a space.

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro – A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!

alt text

Learn More!


<<Return to VBA Examples

Did you find this VBA tutorial useful? Then share it with your friends and colleagues:

You may also like some of this related content...

VBA has many string functions that will allow you to manipulate and work with text
In VBA, you can compare two strings using the StrComp function. In this tutorial, you
Count Number of Words in a String The following VBA function counts the number of
Extract Numerical Portion of String The following function will extract the numerical portion from a
Reverse a String of Text with VBA The VBA Routine below allows the user to
Ads