How to Use the TRIM Function in Excel

The TRIM function in Excel and Google Sheets is designed to eliminate excess spaces from a text string. It ensures that only a single space separates words and removes any spaces at the beginning and end of the text. This functionality is particularly valuable for cleaning up data from imports or correcting inconsistencies in user input that might include extra spaces.

How it Works

The syntax for the TRIM function is consistent across both Excel and Google Sheets:

TRIM(text)

Here, text refers to the string from which you want to remove extra spaces.

Examples

Let’s explore some practical applications of the TRIM function:

Example 1: Removing Extra Spaces

Consider a scenario where you have the text string ” Hello World ” in cell A1. You can apply the TRIM function to clean up the text as shown below:

Original Text Text after TRIM
Hello World Hello World

Applying the formula =TRIM(A1) in another cell will yield the trimmed text.

Example 2: Cleaning up Data

Data imported from external sources often contains spacing inconsistencies. The TRIM function can help standardize this data. For instance, if cell A1 contains “Data  Science” and cell A2 contains “Data  Science “, you can standardize them using TRIM:

Original Text Text after TRIM
Data  Science Data Science
Data  Science  Data Science

By applying =TRIM(A1) and =TRIM(A2) to these cells, you achieve clean and consistent text formatting.

Conclusion

The TRIM function is an essential tool for managing text data in Excel and Google Sheets. It plays a crucial role in standardizing text formats by removing unnecessary spaces, thereby facilitating smoother data analysis and processing.

More information: https://support.microsoft.com/en-us/office/trim-function-410388fa-c5df-49c6-b16c-9e5630b479f9

Other functions
Returns an array of text values from any specified range
Changes full-width (double-byte) English letters or katakana within a character string to half-width (single-byte) characters
Converts a number to text, using the ß (baht) currency format
Returns the character specified by the code number
Removes all nonprintable characters from text
Returns a numeric code for the first character in a text string
Combines the text from multiple ranges and/or strings, but it doesn't provide the delimiter or IgnoreEmpty arguments
Joins several text items into one text item
Changes half-width (single-byte) English letters or katakana within a character string to full-width (double-byte) characters
Converts a number to text, using the $ (dollar) currency format
Checks to see if two text values are identical
Finds one text value within another (case-sensitive)
Formats a number as text with a fixed number of decimals
Changes half-width (single-byte) characters within a string to full-width (double-byte) characters
Returns the leftmost characters from a text value
Returns the number of characters in a text string
Converts text to lowercase
Returns a specific number of characters from a text string starting at the position you specify
Converts text to number in a locale-independent manner
Extracts the phonetic (furigana) characters from a text string
Capitalizes the first letter in each word of a text value
Replaces characters within text
Repeats text a given number of times
Returns the rightmost characters from a text value
Finds one text value within another (not case-sensitive)
Substitutes new text for old text in a text string
Converts its arguments to text
Formats a number and converts it to text
Combines the text from multiple ranges and/or strings, and includes a delimiter you specify between each text value that will be combined If the delimiter is an empty text string, this function will effectively concatenate the ranges
Returns the Unicode character that is references by the given numeric value
Returns the number (code point) that corresponds to the first character of the text
Converts text to uppercase
Converts a text argument to a number
Returns text from any specified value