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

3. Formulas and Functions

3.7 SUBSTITUTE, REPLACE, TRIM, CLEAN and Case Functions

Function Example Result
SUBSTITUTE(text, old, new, [instance]) =SUBSTITUTE("Aurangabad Road","Aurangabad","Sambhaji Nagar") Sambhaji Nagar Road
REPLACE(old_text, start, num_chars, new_text) =REPLACE("9876543210",1,6,"XXXXXX") XXXXXX3210
TRIM(text) =TRIM(" Baner Pune ") Baner Pune
CLEAN(text) removes non-printable characters (codes 0–31), e.g. line breaks
UPPER / LOWER / PROPER =PROPER("sHRADDHA bAGALE") Shraddha Bagale

About this data: Teaching sample for a fictional shop “GreenField Dairy”. Figures and names (e.g. Aarti Kulkarni) are made up for this lesson on substitute replace trim clean and case functions.

SUBSTITUTE replaces what (by text); REPLACE replaces where (by position). TRIM removes leading/trailing spaces and reduces inside spaces to one – but not the non-breaking space CHAR(160) that comes from web pages. For that:

=TRIM(SUBSTITUTE(CLEAN(A2),CHAR(160)," "))

Worked example. Product names from a supplier: " greenvale cow milk 500 ML". =PROPER(TRIM(A2)) → Greenvale Cow Milk 500 Ml. Then fix the unit: =SUBSTITUTE(PROPER(TRIM(A2)),"Ml","ml") → Greenvale Cow Milk 500 ml.

Ravindra Bagale's Tip

"Even after TRIM, the lookup doesn't match" – many students tell me this. The reason is that data coming from the web or a PDF contains CHAR(160), which TRIM does not remove. Check the length with =LEN(A2); if it is more than the visible characters, use SUBSTITUTE(…,CHAR(160)," ").

Practice task

Clean a column of messy area names (extra spaces, wrong case, one line break) into proper case. Mask customer phone numbers so only the last 4 digits show.

Loading practice tasks...

  1. Fix the name case (Easy): The raw name "sHRADDHA bAGALE" is in the wrong case. Fix it so it looks like Shraddha Bagale.
  2. Remove extra spaces (Easy): The raw text " Baner Pune " has extra spaces. Remove them.
  3. Insurance: fix the holder name (Easy): On the Insurance sheet, the holder name "mARIA gARCIA" is in the wrong case. Fix it so it looks like Maria Garcia.
  4. Insurance: small letters (Easy): On the Insurance sheet, make the plan code "HEALTH-PLAN-GOLD" all small letters.
  5. Hide the phone number (Medium): Hide the first 6 digits of the phone number 9876543210 with XXXXXX.
  6. Change a word (Medium): In the address "Aurangabad Road, Sambhaji Nagar", change "Aurangabad" to "Sambhaji Nagar".
  7. Insurance: clean policy number (Medium): On the Insurance sheet, the policy ID " pol-77812 " is messy. Make it look like POL-77812.
  8. Clean product name (Hard): The product name " greenvale cow milk 500 ML" is messy. Make it look like Greenvale Cow Milk 500 Ml (no extra spaces, proper case).
  9. Upper case code (Hard): Make the raw name "sHRADDHA bAGALE" all capital letters.
  10. Insurance: change the dash (Hard): On the Insurance sheet, in "Motor Insurance - Third Party", change " - " to ": ".

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 Substitute Replace Trim Clean And Case Functions?
Card 1: What is Substitute Replace Trim Clean And Case Functions? · Download PNG
Revision card 2: Tiny example — Substitute Replace Trim Clean And Case Functions
Card 2: Tiny example — Substitute Replace Trim Clean And Case Functions · Download PNG
Revision card 3: Checklist — Substitute Replace Trim Clean And Case Functions
Card 3: Checklist — Substitute Replace Trim Clean And Case Functions · Download PNG