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
=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.
|
=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
=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. |
METHOD 4. Excel TRIM function using the Excel built-in function library with links
EXCEL
=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. |
Dim ws As Worksheet
ws.Range("C5") = Application.WorksheetFunction.Trim(" excel is the best 1234 ")
End Sub
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.
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.
Dim ws As Worksheet
ws.Range("C5") = Application.WorksheetFunction.Trim(ws.Range("B5"))
End Sub
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.
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.
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.
=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.