MS Excel: TRIM Function (WS, VBA)

This Excel tutorial explains how to use the Excel TRIM function with syntax and examples.

Description

The Microsoft Excel TRIM function returns a text value with the leading and trailing spaces removed.

Syntax

The syntax for the Microsoft Excel TRIM function is:
TRIM( text )

Parameters or Arguments

text is the text value to remove the leading and trailing spaces from.

Applies To

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 the following type of function:
  • Worksheet function (WS)
  • VBA function (VBA)

Example (as Worksheet Function)

Let's look at some Excel TRIM function examples and explore how to use the TRIM function as a worksheet function in Microsoft Excel:
Microsoft Excel
Based on the spreadsheet above, the following Excel TRIM examples would return:
=TRIM(A1)
Result: "Tech on the Net"

=TRIM(A2)
Result: "1234"

=TRIM(A3)
Result: "alphabet soup"

=TRIM(A4)
Result: "www.techonthenet.com"

=TRIM("  apples ")
Result: "apples"

Example (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 to use the TRIM function in Excel VBA code:
Dim LResult As String

LResult = Trim ("   Alphabet   ")

Total Pageviews

2016 © BiztechCS
Planer theme by BiztechCS