Ravindra BagaleCourses & study guides मराठी Track your progress

5. Data Cleaning A–Z

5.3 Extra Spaces and Non-printable Characters

TRIM extra spaces with example — in 30 seconds

What: TRIM removes spaces at the start and end, and turns double spaces inside the text into single spaces.

Why: "Pune " with a hidden space is not equal to "Pune". COUNTIF and lookups quietly miss those rows.

Tiny example: " Pune " has LEN 7. After =TRIM(A2) it is "Pune" with LEN 4.

First look at the data (before → after):

TRIM extra spaces with example: before and after tables, fictional FreshGo Maharashtra data

Expected result — After TRIM

B: Clean C: LEN
"Pune" 4
"Nashik Road" 11
"Kolhapur" 8

About this data: Teaching sample for a fictional shop “NovaCraft Tools”. Figures and names (e.g. Aamir Khan) are made up for this lesson on extra spaces and non printable characters.

Before table and formula as text

Before — Raw city text (spaces shown inside quotes)

A: Raw =LEN(A2)
" Pune " 7
"Nashik Road" 12
" Kolhapur" 9

About this data: Demo table only — not real customer or company data. Built to practise extra spaces and non printable characters.

Formula / click path

B2: =TRIM(A2)
C2: =LEN(B2)

Do it step by step:

  1. In B2, type =LEN(A2) first to see the hidden spaces.
  2. In C2, type =TRIM(A2).
  3. Copy down and compare the lengths.
  4. Copy column C and use Paste Special › Values over column A.
  5. If LEN is still too big, the data may have non-breaking spaces. Use =SUBSTITUTE(A2,CHAR(160)," ") before TRIM.

Before

Store ID (raw) LEN
" BLK-PUN-01" 12
"BLK-NSK-01 " 13
"AMN-NGP-01" + non-breaking space 11
"BLK-KOP-01" + line break 11

About this data: Made-up rows so you can copy the pattern for extra spaces and non printable characters. Currencies may use ₹, £, € or $.

After

Store ID (clean) LEN
BLK-PUN-01 10
BLK-NSK-01 10
AMN-NGP-01 10
BLK-KOP-01 10

About this data: Fictional worksheet used in class. Safe to edit; nothing here is live production data.

Steps in Excel

  1. Check: =LEN(A2) – more characters than you can see means hidden spaces.
  2. Normal spaces: =TRIM(A2).
  3. Line breaks and control characters: =CLEAN(A2).
  4. Non-breaking spaces from web/PDF copies: =SUBSTITUTE(A2,CHAR(160)," ").
  5. All together: =TRIM(CLEAN(SUBSTITUTE(A2,CHAR(160)," "))) › copy down › Paste Special › Values over the original.
  6. Find & Replace alternative for CHAR(160): Ctrl + H › in Find what hold Alt and type 0160 on the numeric keypad › Replace with a normal space › Replace All.

Ravindra Bagale's Tip

Many students apply TRIM and think "it's clean now", but don't check LEN again. Data from the web or a PDF contains CHAR(160), which TRIM doesn't see. So after cleaning, check a sample with LEN – if you expect 10 characters, you should get exactly 10.

Practice task

Paste a few store IDs copied from a web page, measure LEN, clean them with the combined formula and prove they now match the Stores master using XLOOKUP.

Loading practice tasks...

  1. Clean a name (Easy): Clean the name in B2.
  2. Length of a raw name (Easy): How many characters are in B2?
  3. Remove a double space (Easy): Clean the name in B3.
  4. Clean a city (Easy): Clean the city in C7.
  5. Count extra spaces (Medium): How many extra characters does B5 have? (length minus cleaned length)
  6. Is it really Carlos Diaz? (Medium): Does the cleaned B3 equal "Carlos Diaz"? (TRUE or FALSE)
  7. Hidden space in a city (Medium): Clean the city in C4.
  8. Count hidden characters (Medium): How many characters does CLEAN remove from B6?
  9. Line break to space (Hard): Make B6 read "Neha Deshpande".
  10. Full clean (Hard): Clean B4 fully.
  11. Clean a tracking number (Hard): Clean the AWB in D5.

Quick revision cards

Three standalone cards. Each one explains the idea with its own example. Scan the QR to open this lesson.

Revision card 1: What is Extra Spaces And Non Printable Characters?
Card 1: What is Extra Spaces And Non Printable Characters? · Download PNG
Revision card 2: Tiny example — Extra Spaces And Non Printable Characters
Card 2: Tiny example — Extra Spaces And Non Printable Characters · Download PNG
Revision card 3: Checklist — Extra Spaces And Non Printable Characters
Card 3: Checklist — Extra Spaces And Non Printable Characters · Download PNG