Excel Trim

John Lilleystone • January 21, 2021

Use the TRIM function in Excel to remove whitespaces

Sometimes you get data which contains additional invisible whitespaces at either the front of end of a cell. These can cause problems when trying to perform other functions on the data such as VLOOKUP for example. Excel has a built in function called TRIM which will remove them for you.

Someone sent me some information the other day and I needed to a VLOOKUP on the data they sent me against some data. However despite having the right formula it returned an error. On closer inspection, it turned out that the data supplied to me had invisible spaces at the start and end of the product code which caused my VLOOKUP to fail. It was quite a lot of data and I didn’t want to have to manually tidy up each cell as it would’ve taken me hours.  TRIM to the rescue.

Here’s an example – I want to pull in the descriptions from my product list on the left into my sales table on the right. A quick VLOOKUP should sort that out in a jiffy – however I get #N/A even though the part numbers in both tables appear to match. If you look closely though you’ll see that there’s a cheeky little space before the product code on the left table.


So we need to remove the spaces and there’s an Excel function called TRIM which will do just that.

 

Insert a new column and enter =TRIM(B2) and press enter. Copy the formula down to the end of your dataset. Then Copy the values in this new column and Paste-Special over the original values in column B.New Paragraph

Boom! VLOOKUP now works and descriptions get pulled in.

excel iferror error alternate result
By john lilleystone April 11, 2020
Replace ugly Excel errors returned by a formula with something more appropriate and pleasing to the eye.
excel transpose
By john lilleystone March 14, 2020
Transpose and paste a vertical column of data horizontally into a row
edit hyperlink
By john lilleystone March 14, 2020
Edit a hyperlink in Outlook 2016
emoji symbol
By john lilleystone March 14, 2020
insert an emoji or symbol into your application
sparklines
By john lilleystone March 1, 2020
Add Sparklines to Excel tables to show trends in the data
random numbers randbetween
By john lilleystone March 1, 2020
Use the RANDBETWEEN function in Excel to randomly generate numbers between a specified upper and lower threshold.
DATEADD MSQUERY
By john lilleystone March 1, 2020
Don't waste time manually editing queries to move the date period on one month. This blog explains how to use DATEADD to dynamically shift the dates on one month on each refresh
By john lilleystone February 29, 2020
Import text files into Excel and use the Text to Columns wizard to separate the data into columns
By john lilleystone February 26, 2020
Return the last non-zero value in a row in Excel
By john lilleystone February 4, 2020
Extract values or strings from a cell from either the left, middle or right part of the cell
Show More