Introduction
Real-world Excel data is often messy. Names may contain extra spaces, emails may be mixed with other information, product codes may have different formats, and important details may be hidden inside longer text. In this chapter, you will practice extracting and cleaning data using functions such as LEFT, RIGHT, MID, FIND, SEARCH, TRIM, CLEAN, SUBSTITUTE, TEXTBEFORE, TEXTAFTER, and TEXTSPLIT. These questions are designed to help you handle practical Excel data-cleaning tasks. Text Extraction and Data Cleaning
Practice question with solutions to help you understand the concepts.
Question 1: Extract Username from Email Address
Problem Statement
A customer database contains email addresses. Extract the username appearing before the @ symbol.
Excel Data
| Username | |
|---|---|
| rahul.sharma@gmail.com | |
| priya.verma@yahoo.com | |
| amit.kumar@outlook.com | |
| neha.kapoor@gmail.com | |
| arjun.singh@company.com |
Solution
In B2, enter:
=LEFT(A2,FIND("@",A2)-1)
Copy the formula down.
Expected Output
| Username | |
|---|---|
| rahul.sharma@gmail.com | rahul.sharma |
| priya.verma@yahoo.com | priya.verma |
| amit.kumar@outlook.com | amit.kumar |
| neha.kapoor@gmail.com | neha.kapoor |
| arjun.singh@company.com | arjun.singh |
Question 2: Extract Domain from Email Address
Problem Statement
Extract everything after the @ symbol from each email address.
Excel Data
Solution
In B2, enter:
=RIGHT(A2,LEN(A2)-FIND("@",A2))
Copy down.
Expected Output
| Domain | |
|---|---|
| rahul@gmail.com | gmail.com |
| priya@yahoo.com | yahoo.com |
| amit@outlook.com | outlook.com |
| neha@company.com | company.com |
| arjun@gmail.com | gmail.com |
Question 3: Extract Product Category from a Product Code
Problem Statement
Product codes follow this format:
ELEC-LAP-101
The first part represents the product category. Extract the category.
Excel Data
| Product Code | Category |
|---|---|
| ELEC-LAP-101 | |
| COMP-KEY-102 | |
| HOME-CHA-103 | |
| ELEC-MON-104 | |
| COMP-MOU-105 |
Solution
In B2, enter:
=LEFT(A2,FIND("-",A2)-1)
Copy down.
Expected Output
| Product Code | Category |
|---|---|
| ELEC-LAP-101 | ELEC |
| COMP-KEY-102 | COMP |
| HOME-CHA-103 | HOME |
| ELEC-MON-104 | ELEC |
| COMP-MOU-105 | COMP |
Question 4: Extract Product Number from the End of a Code
Problem Statement
The last three characters of each product code represent the product number. Extract that number.
Excel Data
| Product Code | Product Number |
|---|---|
| ELEC-LAP-101 | |
| COMP-KEY-205 | |
| HOME-CHA-310 | |
| ELEC-MON-415 | |
| COMP-MOU-520 |
Solution
In B2, enter:
=RIGHT(A2,3)
Copy down.
Expected Output
| Product Code | Product Number |
|---|---|
| ELEC-LAP-101 | 101 |
| COMP-KEY-205 | 205 |
| HOME-CHA-310 | 310 |
| ELEC-MON-415 | 415 |
| COMP-MOU-520 | 520 |
Question 5: Extract the Middle Section Using MID
Problem Statement
Each employee ID follows this format:
EMP-DEL-101
The middle section represents the city code. Extract it.
Excel Data
| Employee ID | City Code |
|---|---|
| EMP-DEL-101 | |
| EMP-NOI-102 | |
| EMP-JAI-103 | |
| EMP-PUN-104 | |
| EMP-MUM-105 |
Solution
In B2, enter:
=MID(A2,5,3)
Copy down.
Expected Output
| Employee ID | City Code |
|---|---|
| EMP-DEL-101 | DEL |
| EMP-NOI-102 | NOI |
| EMP-JAI-103 | JAI |
| EMP-PUN-104 | PUN |
| EMP-MUM-105 | MUM |
MID starts at a specified position and extracts a specified number of characters.
Question 6: Clean Names with TRIM and PROPER
Problem Statement
Employee names were imported from another system. They contain extra spaces and inconsistent capitalization. Clean and standardize the names.
Excel Data
| Raw Name | Clean Name |
|---|---|
rahul sharma | |
PRIYA verma | |
amit KUMAR | |
neha KAPOOR | |
ARJUN singh |
Solution
In B2, enter:
=PROPER(TRIM(A2))
Copy down.
Expected Output
| Raw Name | Clean Name |
|---|---|
rahul sharma | Rahul Sharma |
PRIYA verma | Priya Verma |
amit KUMAR | Amit Kumar |
neha KAPOOR | Neha Kapoor |
ARJUN singh | Arjun Singh |
Question 7: Remove Unwanted Characters from Phone Numbers
Problem Statement
Phone numbers have been stored using different separators. Convert them into a consistent format containing only the digits.
Excel Data
| Raw Phone | Clean Phone |
|---|---|
| 987-654-3210 | |
| 987 654 3211 | |
| 987.654.3212 | |
| 987-654-3213 | |
| 987 654 3214 |
Solution
For values containing hyphens, spaces, or periods, use nested SUBSTITUTE functions.
In B2, enter:
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,"-","")," ",""),".","")
Copy down.
Expected Output
| Raw Phone | Clean Phone |
|---|---|
| 987-654-3210 | 9876543210 |
| 987 654 3211 | 9876543211 |
| 987.654.3212 | 9876543212 |
| 987-654-3213 | 9876543213 |
| 987 654 3214 | 9876543214 |
This approach removes the three unwanted separators.
Question 8: Extract Name and City from Combined Data
Problem Statement
Customer information is stored in this format:
Rahul Sharma - Delhi
Extract the customer name and city into separate columns.
Excel Data
| Combined Information | Customer Name | City |
|---|---|---|
| Rahul Sharma – Delhi | ||
| Priya Verma – Noida | ||
| Amit Kumar – Jaipur | ||
| Neha Kapoor – Pune | ||
| Arjun Singh – Mumbai |
Solution
Customer Name
In B2, enter:
=TEXTBEFORE(A2," - ")
City
In C2, enter:
=TEXTAFTER(A2," - ")
Copy both formulas down.
Expected Output
| Combined Information | Customer Name | City |
|---|---|---|
| Rahul Sharma – Delhi | Rahul Sharma | Delhi |
| Priya Verma – Noida | Priya Verma | Noida |
| Amit Kumar – Jaipur | Amit Kumar | Jaipur |
| Neha Kapoor – Pune | Neha Kapoor | Pune |
| Arjun Singh – Mumbai | Arjun Singh | Mumbai |
Note: TEXTBEFORE and TEXTAFTER are available in newer Excel versions.
Question 9: Split a Full Name into Separate Columns
Problem Statement
Names are stored in a single cell. Split the first name, middle name, and last name into separate columns.
Excel Data
| Full Name | First Name | Middle Name | Last Name |
|---|---|---|---|
| Rahul Kumar Sharma | |||
| Priya Singh Verma | |||
| Amit Raj Kumar | |||
| Neha Priya Kapoor | |||
| Arjun Dev Singh |
Solution
In B2, enter:
=TEXTSPLIT(A2," ")
Excel will automatically spill the three parts into the adjacent cells.
Expected Output
| Full Name | First Name | Middle Name | Last Name |
|---|---|---|---|
| Rahul Kumar Sharma | Rahul | Kumar | Sharma |
| Priya Singh Verma | Priya | Singh | Verma |
| Amit Raj Kumar | Amit | Raj | Kumar |
| Neha Priya Kapoor | Neha | Priya | Kapoor |
| Arjun Dev Singh | Arjun | Dev | Singh |
TEXTSPLIT is useful when a single cell contains multiple pieces of information separated by a delimiter.
Question 10: Complete Data Cleaning and Extraction Task
Problem Statement
You receive customer records in this format:
RAHUL SHARMA | rahul@gmail.com | DELHI
The data contains extra spaces and inconsistent capitalization.
Create three clean columns:
- Customer Name
- City
Excel Data
| Raw Customer Data | Customer Name | City | |
|---|---|---|---|
| ` RAHUL SHARMA | rahul@gmail.com | DELHI ` | |
| ` PRIYA VERMA | priya@yahoo.com | NOIDA ` | |
| ` AMIT KUMAR | amit@outlook.com | JAIPUR` | |
| `NEHA KAPOOR | neha@gmail.com | PUNE ` | |
| ` ARJUN SINGH | arjun@company.com | MUMBAI ` |
Solution
Customer Name
In B2, enter:
=PROPER(TRIM(TEXTBEFORE(A2,"|")))
In C2, enter:
=LOWER(TRIM(TEXTBEFORE(TEXTAFTER(A2,"|"),"|")))
City
In D2, enter:
=PROPER(TRIM(TEXTAFTER(A2,"|",2)))
Copy all three formulas down.
Expected Output
| Raw Customer Data | Customer Name | City | |
|---|---|---|---|
RAHUL SHARMA | rahul@gmail.com | DELHI | Rahul Sharma | rahul@gmail.com | Delhi |
PRIYA VERMA | priya@yahoo.com | NOIDA | Priya Verma | priya@yahoo.com | Noida |
AMIT KUMAR | amit@outlook.com | JAIPUR | Amit Kumar | amit@outlook.com | Jaipur |
NEHA KAPOOR | neha@gmail.com | PUNE | Neha Kapoor | neha@gmail.com | Pune |
ARJUN SINGH | arjun@company.com | MUMBAI | Arjun Singh | arjun@company.com | Mumbai |
This combines text extraction and data cleaning in one practical example.
Key Takeaways
LEFTextracts characters from the beginning of text.RIGHTextracts characters from the end.MIDextracts characters from a specific position.FINDcan locate a character or delimiter before extracting text.SEARCHcan also locate text without case sensitivity.TRIMremoves unnecessary spaces.CLEANremoves non-printable characters.SUBSTITUTEcan remove or replace unwanted characters.TEXTBEFOREextracts text before a specified delimiter.TEXTAFTERextracts text after a specified delimiter.TEXTSPLITcan split one cell into multiple cells.PROPERis useful for standardizing names and city names.LOWERis useful for standardizing email addresses.- Combining extraction and cleaning functions is common when preparing imported data for analysis.
FAQs
1. What is text extraction in Excel?
Text extraction means taking a specific part of a larger text value. For example, extracting the username from an email address or the city from an address.
2. Which Excel functions are used for text extraction?
Common functions include:
LEFT
RIGHT
MID
FIND
SEARCH
TEXTBEFORE
TEXTAFTER
TEXTSPLIT
3. How can I extract text before a specific character?
In newer Excel versions, you can use TEXTBEFORE.
=TEXTBEFORE(A2,"@")
For older Excel versions, you can combine LEFT and FIND.
=LEFT(A2,FIND("@",A2)-1)
4. How can I extract text after a specific character?
Use TEXTAFTER in newer Excel versions.
=TEXTAFTER(A2,"@")
For older versions, RIGHT, LEN, and FIND can be combined.
5. How do I remove extra spaces from imported data?
Use TRIM.
=TRIM(A2)
For names, you can combine it with PROPER:
=PROPER(TRIM(A2))
6. How do I remove hyphens from a phone number?
Use SUBSTITUTE.
=SUBSTITUTE(A2,"-","")
For multiple unwanted characters, you can nest SUBSTITUTE functions.
7. What is TEXTSPLIT used for?
TEXTSPLIT separates text into multiple cells using a delimiter.
For example:
=TEXTSPLIT(A2," ")
splits text wherever a space occurs.
8. What is the difference between TEXTBEFORE and LEFT?
LEFT extracts a specified number of characters, while TEXTBEFORE extracts everything before a specified delimiter.
For example:
=LEFT(A2,5)
extracts five characters, whereas:
=TEXTBEFORE(A2,"-")
extracts everything before the hyphen.
9. Why should data be cleaned before analysis?
Messy data can cause problems with sorting, filtering, searching, matching, and calculations. Cleaning the data first makes it more consistent and easier to analyze.
10. Can text extraction and data cleaning functions be combined?
Yes. Combining functions is one of the most useful Excel techniques for real-world data.
For example:
=PROPER(TRIM(TEXTBEFORE(A2,"|")))
extracts the required part and cleans its spaces and capitalization at the same time.
Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.
