Excel TRIM Function

The Excel TRIM function removes the spaces at the start and end of the text and also removes the unnecessary spaces between words, leaving only a single space between words and numbers that form part of the text

Example: Excel TRIM Function

Excel TRIM Function

METHOD 1. Excel TRIM Function using hardcoded values

EXCEL

=TRIM(" excel is the best 1234 ")
Result in cell C5 (excel is the best 1234) - removes the spaces at the start and end of the text and also removes the unnecessary spaces between words, leaving only a single space between words.

METHOD 2. Excel TEXT Function using links

EXCEL

=TRIM(B5)
Result in cell C5 (excel is the best 1234) - removes the spaces at the start and end of the text and also removes the unnecessary spaces between words, leaving only a single space between words.

METHOD 3. Excel TRIM function using the Excel built-in function library with hardcoded values

EXCEL

Formulas tab > Function Library group > Text > TRIM > populate the input box

=TRIM(" excel is the best 1234 ")
Note: in this example we are removing the spaces at the start and end of the text and also the unnecessary spaces between the words and numbers, leaving only a single space between the words and numbers.
Built-in Excel TRIM Function using hardocded values

METHOD 4. Excel TRIM function using the Excel built-in function library with links

EXCEL

Formulas tab > Function Library group > Text > TRIM > populate the input box

=TRIM(B5)
Note: in this example we are removing the spaces at the start and end of the text in cell (B5) and also the unnecessary spaces between the words and numbers, leaving only a single space between the words and numbers.
Built-in Excel TRIM Function using links

METHOD 1. Excel TRIM function using VBA with hardcoded values

VBA

Sub Excel_TRIM_Function()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("TRIM")

'apply the Excel TRIM function
ws.Range("C5") = Application.WorksheetFunction.Trim(" excel is the best 1234 ")

End Sub

OBJECTS
Worksheets: The Worksheets object represents all of the worksheets in a workbook, excluding chart sheets.
Range: The Range object is a representation of a single cell or a range of cells in a worksheet.
PREREQUISITES
Worksheet Name: Have a worksheet named TRIM.

ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("C5") in the VBA code to any cell in the worksheet, that doesn't conflict with the formula.

METHOD 2. Excel TRIM function using VBA with links

VBA

Sub Excel_TRIM_Function()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("TRIM")

'apply the Excel TRIM function
ws.Range("C5") = Application.WorksheetFunction.Trim(ws.Range("B5"))

End Sub

OBJECTS
Worksheets: The Worksheets object represents all of the worksheets in a workbook, excluding chart sheets.
Range: The Range object is a representation of a single cell or a range of cells in a worksheet.
PREREQUISITES
Worksheet Name: Have a worksheet named TRIM.
Text: Have the text from which you want to remove the extra spaces in cell ("B5").

ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("C5") in the VBA code to any cell in the worksheet, that doesn't conflict with the formula.
Text: Select the text from which you want to remove the extra spaces by changing the cell reference ("B5") to any range in the worksheet, that doesn't conflict with the formula.

Usage of the Excel TRIM function and formula syntax

EXPLANATION

DESCRIPTION
The Excel TRIM function removes the spaces at the start and end of the text and also removes the unnecessary spaces between words, leaving only a single space between words and numbers that form part of the text.
SYNTAX
=TRIM(text)

ARGUMENTS
text: (Required) The text from which to remove the spaces at the start and end of the text and unnecessary spaces between words and numbers.