Excel: Trim Function
In Excel, the Trim function returns a text value with the leading and trailing spaces removed.
The syntax for the Trim function is:
Trim( text )
text is the text value to remove the leading and trailing spaces from.
Applies To:
- Excel 2007, Excel 2003, Excel XP, Excel 2000
For example:
Let's take a look at an example:

Based on the Excel spreadsheet above:
=Trim(A1) would return "Tech on the Net" =Trim(A2) would return "1234" =Trim(A3) would return "alphabet soup" =Trim(" apples ") would return "apples"
VBA Code
The Trim function can also be used in VBA code. For example:
Dim LResult As String
LResult = Trim (" Alphabet ")
The variable LResult would now contain the value of "Alphabet".