Excel Text Functions: LEFT, RIGHT, MID, TEXTSPLIT, TEXTBEFORE and More

Excel text functions LEFT RIGHT MID TEXTSPLIT TEXTBEFORE

Real data rarely arrives clean. Names come in one column when you need two, product codes hide the category inside them, and emails need to be split into user and domain. Excel's text functions fix all of this with formulas that update when the data changes.

This guide covers the classic functions that work in every version (LEFT, RIGHT, MID, LEN, FIND) and the newer Excel 365 functions that make most tasks much easier (TEXTBEFORE, TEXTAFTER, TEXTSPLIT).

Quick reference

FunctionWhat it doesExampleResult
LEFTFirst n characters=LEFT("INV-2026-045", 3)INV
RIGHTLast n characters=RIGHT("INV-2026-045", 3)045
MIDCharacters from a position=MID("INV-2026-045", 5, 4)2026
LENNumber of characters=LEN("Excel")5
FINDPosition of text (case-sensitive)=FIND("-", "INV-2026-045")4
SEARCHPosition of text (not case-sensitive, allows wildcards)=SEARCH("inv", "INV-2026")1
TEXTBEFOREText before a delimiter=TEXTBEFORE("asha@abc.com", "@")asha
TEXTAFTERText after a delimiter=TEXTAFTER("asha@abc.com", "@")abc.com
TEXTSPLITSplit into many cells=TEXTSPLIT("a,b,c", ",")a | b | c

The classic functions

LEFT, RIGHT and MID

=LEFT(text, num_chars)
=RIGHT(text, num_chars)
=MID(text, start_num, num_chars)

They work perfectly when the parts have a fixed length, such as a 3-letter prefix or a 6-digit PIN code at the end of an address.

Combining with FIND for variable lengths

When the parts vary in length, use FIND to locate the separator. For a full name "Priya Sharma" in A2:

First name: =LEFT(A2, FIND(" ", A2) - 1)
Last name:  =MID(A2, FIND(" ", A2) + 1, LEN(A2))

FIND returns 6 (the position of the space), so LEFT takes 5 characters. For the last name, MID starts after the space; asking for LEN(A2) characters simply means "everything that is left".

Extract the domain from an email (older Excel)

=MID(A2, FIND("@", A2) + 1, LEN(A2))

The Excel 365 functions

If you have Microsoft 365 or Excel for the web, these replace most LEFT/MID/FIND combinations.

TEXTBEFORE and TEXTAFTER

=TEXTBEFORE(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])
=TEXTAFTER(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])

Examples with A2 = North-Laptop-L2045:

  • =TEXTBEFORE(A2, "-") returns North.
  • =TEXTAFTER(A2, "-") returns Laptop-L2045 (everything after the first hyphen).
  • =TEXTAFTER(A2, "-", -1) returns L2045. A negative instance counts from the end, so -1 means "after the last hyphen".
  • =TEXTBEFORE(TEXTAFTER(A2, "-"), "-") returns Laptop, the middle part.

Use the last argument to avoid #N/A when the delimiter is missing: =TEXTAFTER(A2, "@", , , , "No email").

TEXTSPLIT

=TEXTSPLIT(text, col_delimiter, [row_delimiter], [ignore_empty], [match_mode], [pad_with])
  • =TEXTSPLIT(A2, "-") spills North | Laptop | L2045 into three cells.
  • =TRIM(TEXTSPLIT("Excel; SQL;Power BI", ";")) splits on semicolons and removes the leftover spaces.
  • =TEXTSPLIT(A2, , ",") splits by row instead of by column.

Make sure the cells to the right are empty, or you will get a #SPILL! error.

Cleaning text

  • =TRIM(A2) removes extra spaces.
  • =CLEAN(A2) removes non-printing characters, common in data copied from other systems.
  • =UPPER(A2), =LOWER(A2), =PROPER(A2) change case. PROPER turns "priya sharma" into "Priya Sharma".
  • =SUBSTITUTE(A2, "-", "") removes all hyphens; =SUBSTITUTE(A2, " ", "") removes all spaces.
  • Non-breaking spaces from websites are not removed by TRIM. Use =TRIM(SUBSTITUTE(A2, CHAR(160), " ")).

Joining text

  • =A2 & " " & B2 joins first and last name.
  • =TEXTJOIN(", ", TRUE, A2:A10) joins a whole range with commas and skips blanks.
  • =TEXT(B2, "dd-mmm-yyyy") formats a date as text inside a sentence: ="Invoice date: " & TEXT(B2, "dd-mmm-yyyy").

Practical examples

1. Get the 10-digit mobile number from "+91 98765 43210"

=RIGHT(SUBSTITUTE(A2, " ", ""), 10)

Removes the spaces, then keeps the last 10 digits: 9876543210.

2. Count the words in a cell

=IF(TRIM(A2)="", 0, LEN(TRIM(A2)) - LEN(SUBSTITUTE(TRIM(A2), " ", "")) + 1)

Counts the spaces between words and adds one.

3. Check whether a cell contains a word

=IF(ISNUMBER(SEARCH("refund", A2)), "Refund", "Other")

Useful for tagging customer comments or transaction descriptions.

4. Turn text numbers into real numbers

Numbers extracted with LEFT, MID or TEXTAFTER are text. Add -- or use VALUE so SUM and lookups work: =--TEXTAFTER(A2, "-", -1) or =VALUE(MID(A2, 5, 4)).

Formula or Flash Fill or Power Query?

MethodUse when
Flash Fill (Ctrl + E)One-time fix; Excel guesses the pattern from your example. Does not update.
FormulasData changes and results must update automatically.
Power Query (Split Column)Large files or a cleaning task you repeat every month.

Practice task

In a column of codes like EAST-Mobile-M1180, extract the region in proper case ("East"), the product, and the numeric part as a number (1180). Do it once with TEXTBEFORE/TEXTAFTER and once with LEFT/MID/FIND.

Next: remove repeated rows with 5 ways to remove duplicates, or look up the cleaned codes with XLOOKUP.

Tags

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Learn Excel, Power BI, and Finance in Simple Hindi and English Follow step-by-step tutorials and practical examples designed for students, job seekers, and working professionals. We cover Power BI dashboards, DAX formulas, Excel tricks, financial literacy, and AI tools.