MS Excel: TRIM Function (WS, VBA)
The Microsoft Excel TRIM function returns a text value with the leading and trailing spaces removed.
TRIM Function (Syntax)
The syntax for the Microsoft Excel TRIM function is:
TRIM( text )
text is the text value to remove the leading and trailing spaces from.
The TRIM function can be used in the following versions of Microsoft Excel:
- Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000
Type of Excel Function
The TRIM function can be used in Microsoft Excel as:
- Worksheet function (WS)
- VBA function (VBA)
TRIM Examples (as Worksheet Function)
Let's look at some Excel TRIM function examples and explore how you would use the TRIM function as a worksheet function in Microsoft Excel:
Based on the Excel spreadsheet above, the following TRIM function examples would return:
|=TRIM(A1)||would return "Tech on the Net"|
|=TRIM(A2)||would return "1234"|
|=TRIM(A3)||would return "alphabet soup"|
|=TRIM(A4)||would return "www.techonthenet.com"|
|=TRIM(" apples ")||would return "apples"|
TRIM Examples (as VBA Function)
The TRIM function can also be used in VBA code in Microsoft Excel.
Let's look at some Excel TRIM function examples and explore how you would use the TRIM function in Excel VBA code:
Dim LResult As String LResult = Trim (" Alphabet ")
The variable LResult would now contain the value of "Alphabet".