function to remove spaces
The LTrim, RTrim, and Trim functions remove spaces from the ends of strings. To remove other forms of white space, such as tab characters, use the String.Trim method. This example uses the LTrim function to remove leading spaces and the RTrim function to remove trailing spaces from a string variable. It uses the Trim function to remove both types of spaces. ' Initializes string. Dim TestString As String =  <-Trim->  Dim TrimString As String ' Returns <-Trim-> .
Remove all spaces with the Replace function. Sometimes, we want to remove all spaces between character and numbers in a range, we can use Replace function to solve it. 1. Highlight the range that you want to remove all spaces. 2. Click Home > Find & Select > Replaceâ¦, the Find and Replace dialog box will pop out. 3. In the Find what box, press the space bar once, donât input anything in the Replace with box, then click Replace All.