VBA code to remove white spaces from a string in excel

VBA code to remove white spaces from a string in excel. Simple method is, use Replace() function.

stringToPrint = Replace(stringToPrint, " ", "")

Example:

Sub removeWhiteSpaces()
Dim stringToPrint
stringToPrint = "Please Remove White Spaces"
stringToPrint = Replace(stringToPrint, " ", "")
MsgBox (stringToPrint) ' Printing the string after removing white spaces
End Sub

Output:

remove-white-spaces-VBA-macro

About the Author

SRINI S

A passionate blogger. Love to share solutions and best practices on wordpress hosting, issues and fixes, excel VBA macros and other apps

Leave a Reply

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