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: