LEFT, RIGHT and MID Functions in Excel: Extract Text Like a Pro

LEFT, RIGHT and MID Function in Excel feature image for tutorial blog
Learn how to use LEFT, RIGHT, and MID in Excel to extract text from any position. Covers FIND, LEN combinations, email splitting, file extensions, name extraction, and more.

Raw data rarely arrives in the exact format you need. Product codes, email addresses, phone numbers, and file names all contain segments that you need to split apart. The LEFT, RIGHT, and MID functions are Excel's core text-extraction tools. LEFT pulls characters from the beginning of a string, RIGHT pulls from the end, and MID pulls from any position in the middle. Together, they handle the vast majority of text-splitting tasks — without any add-ins or formulas longer than one line.

Availability: LEFT, RIGHT, and MID work in every Excel version, including Microsoft 365, Excel 2024, 2021, 2019, 2016, and earlier. No dynamic array support is required.

What Do LEFT, RIGHT, and MID Do?

Each function targets a different part of a text string. LEFT starts from character 1. RIGHT starts from the last character and works backward. MID, by contrast, starts from any character position you specify. The visual below shows how all three work on the same string.

String: "PROD-GB-2026"
P1
R2
O3
D4
-5
G6
B7
-8
29
010
211
612

■ LEFT(A1,4) → "PROD" ■ MID(A1,6,2) → "GB" ■ RIGHT(A1,4) → "2026"

Syntax for All Three Functions

LEFT

=LEFT(text, [num_chars])

num_chars defaults to 1

=LEFT("PROD-GB",4)

→ "PROD"

=LEFT(A2,3)

→ first 3 chars of A2

RIGHT

=RIGHT(text, [num_chars])

num_chars defaults to 1

=RIGHT("PROD-2026",4)

→ "2026"

=RIGHT(A2,3)

→ last 3 chars of A2

MID

=MID(text, start, num_chars)

All 3 arguments required

=MID("PROD-GB-26",6,2)

→ "GB"

=MID(A2,4,5)

→ 5 chars from pos 4

MID requires all three arguments: Unlike LEFT and RIGHT, MID always needs a start position and a character count. If num_chars exceeds the remaining length of the string, MID simply returns everything to the end — it does not error.

Example 1: Extract a Fixed-Length Code Segment

Fixed-length codes are the simplest case. When every code follows the same structure — for example, a 3-character country prefix, a hyphen, and a 4-digit year — you can extract each part with a hardcoded character count. This works well for product codes, order IDs, and account numbers.

1
Split a structured product code into its three components
A — Code
B — Category (LEFT 3)
C — Region (MID 5,2)
D — Year (RIGHT 4)
Structure
PRD-GB-2026
PRD
GB
2026
CAT-REG-YEAR
SVC-US-2025
SVC
US
2025
CAT-REG-YEAR
Category — first 3 characters: =LEFT(A2, 3) Region — 2 characters starting at position 5: =MID(A2, 5, 2) Year — last 4 characters: =RIGHT(A2, 4)
All three formulas copy down the column without adjustment. The character counts stay the same because every code follows an identical format.

Example 2: Extract Text Before or After a Delimiter

Variable-length strings need a smarter approach. Instead of a fixed character count, you find the delimiter position first using FIND or SEARCH. Then you use that position to calculate exactly how many characters to extract with LEFT or RIGHT.

How to Use FIND with LEFT and RIGHT

FIND returns the character position of a delimiter — such as "@" in an email address, or "/" in a file path. Consequently, you can subtract 1 from that position to get everything before the delimiter, and use LEN minus that position to get everything after it.

2
Split an email address into username and domain
A — Email
B — Username (LEFT)
C — Domain (RIGHT)
sarah@excelguru.io
sarah
excelguru.io
james.kirk@company.co.uk
james.kirk
company.co.uk
FIND returns the position of "@" in the email string. Username — everything to the LEFT of "@": =LEFT(A2, FIND("@", A2) - 1) Domain — everything to the RIGHT of "@": LEN gives total length; subtracting the @ position gives characters after it. =RIGHT(A2, LEN(A2) - FIND("@", A2)) Same pattern works for any delimiter — e.g. hyphen, slash, or comma: =LEFT(A2, FIND("-", A2) - 1) Everything before the first hyphen =RIGHT(A2, LEN(A2) - FIND("-", A2)) Everything after the first hyphen
FIND vs SEARCH: FIND is case-sensitive. SEARCH is case-insensitive. For most delimiters like "@", "-", and "/" this makes no difference. However, when extracting parts based on a letter — for example, the first "S" — use SEARCH if you want to match both uppercase and lowercase.

Example 3: Extract a File Extension with RIGHT and FIND

File extensions vary in length — ".csv" has 4 characters, while ".xlsx" has 5 and ".txt" has 4. Therefore, a fixed character count will not work reliably. Instead, find the last dot and use RIGHT to extract everything after it.

3
Extract the file name and extension from a full file path
A — Filename
B — Name only (LEFT)
C — Extension (RIGHT)
sales_report.xlsx
sales_report
xlsx
budget.v2.csv
budget.v2
csv
FIND returns the position of the dot. File name — everything before the last dot: =LEFT(A2, FIND(".", A2) - 1) Extension — everything after the last dot (excludes the dot itself): LEN minus the dot position leaves just the extension characters. =RIGHT(A2, LEN(A2) - FIND(".", A2)) For filenames with multiple dots (e.g. budget.v2.csv), use SUBSTITUTE + FIND to locate the LAST dot: =RIGHT(A2, LEN(A2) - FIND("*", SUBSTITUTE(A2, ".", "*", LEN(A2) - LEN(SUBSTITUTE(A2, ".", "")))))

Example 4: Extract the First Name and Last Name

Full names stored as "First Last" in a single cell are one of the most common data-cleaning challenges. LEFT with FIND handles the first name. RIGHT with LEN and FIND handles the last name. Additionally, TRIM cleans up any stray spaces that might cause blank results.

4
Split "First Last" names into two separate columns
A — Full name
B — First name
C — Last name
Sarah Connor
Sarah
Connor
James T. Kirk
James
T. Kirk
First name — everything before the first space: =LEFT(A2, FIND(" ", A2) - 1) Last name — everything after the first space: =RIGHT(A2, LEN(A2) - FIND(" ", A2)) Safer version — TRIM removes accidental extra spaces: =TRIM(=LEFT(A2, FIND(" ", A2) - 1)) =TRIM(=RIGHT(A2, LEN(A2) - FIND(" ", A2)))
Consider TEXTSPLIT in Excel 365: If you use Microsoft 365, the TEXTSPLIT function splits text by a delimiter in one step: =TEXTSPLIT(A2," "). This spills first and last names into adjacent cells automatically. For older versions, however, LEFT and RIGHT with FIND remain the most compatible solution.

Example 5: Extract the Middle Segment Between Two Delimiters

MID is at its most powerful when you need something from the middle of a string — between two known delimiters. The formula finds the first delimiter, adds 1 to skip it, then finds the second delimiter to calculate the length. Consequently, it handles variable-length middle segments reliably.

5
Extract the region code from between two hyphens in a product code
A — Full code
B — Middle segment (MID)
Segment
PRD-EMEA-2026
EMEA
4 chars
SVC-US-2025
US
2 chars
HW-APAC-2024
APAC
4 chars
Find positions of the two hyphens, then extract what is between them. p1 = position of first "-", p2 = position of second "-": MID starts one character after the first hyphen (p1+1). Length = p2 minus p1 minus 1 (excludes both hyphens). =MID(A2, FIND("-", A2) + 1, FIND("-", A2, FIND("-", A2) + 1) - FIND("-", A2) - 1 ) Explanation: FIND("-", A2) → position of first "-" (e.g. 4 for "PRD-") FIND("-", A2, p1+1) → position of second "-" (e.g. 9 for "EMEA-") p2 - p1 - 1 → characters between the hyphens (4 = "EMEA")
The nested FIND gives FIND its third argument (start position), which tells it to look for the second hyphen starting from after the first one. This technique works for any delimiter and any middle segment length.

Example 6: Dynamic Extraction with LEN

LEN counts the total characters in a string. Combined with LEFT, RIGHT, and MID, it enables dynamic formulas that adapt to any string length. For example, you can remove a known prefix or suffix, or extract everything except the last N characters.

6
Use LEN to remove fixed prefixes, suffixes, and build dynamic extractions
Remove a known 4-character prefix (e.g. "REF-" from "REF-29847"): LEN minus 4 gives the number of remaining characters. =RIGHT(A2, LEN(A2) - 4) REF-29847 → 29847 Remove the last 3 characters (e.g. strip a suffix like " GB"): LEN minus 3 gives the length up to the suffix. =LEFT(A2, LEN(A2) - 3) London GB → London Extract everything except the first and last character: =MID(A2, 2, LEN(A2) - 2) [hello] → hello (strips the square brackets) Reverse check — is the last character a specific value? =RIGHT(A2, 1) = "!" Returns TRUE if the string ends with an exclamation mark
LEN + SUBSTITUTE counts occurrences: =LEN(A2) - LEN(SUBSTITUTE(A2,"-","")) counts how many hyphens appear in A2. This is useful for validating that a code has the expected number of delimiters before you try to split it.

How to Fix Common Errors

#VALUE! from FIND or SEARCH

FIND returns #VALUE! when the delimiter does not exist in the string. For instance, if one row contains no "@" symbol, the email formula will error. Wrap the entire formula in IFERROR to handle those cases cleanly: =IFERROR(LEFT(A2, FIND("@",A2)-1), A2).

Result is blank or shows spaces

The source data contains leading or trailing spaces that FIND picks up as part of the string. As a result, the extracted text shifts by one or more characters. Always clean source data with TRIM before extracting. Wrap the text argument in TRIM: =LEFT(TRIM(A2), FIND(" ", TRIM(A2))-1).

MID returns more characters than expected

If num_chars in MID is larger than the remaining string, MID simply returns everything to the end without an error. This is intentional behaviour. However, if you expected a fixed length and got more characters, recheck your start position — it may be off by one.

Excel 365 alternative: In Microsoft 365, TEXTBEFORE and TEXTAFTER provide a cleaner way to extract text around a delimiter. For example, =TEXTBEFORE(A2,"@") returns everything before "@" in a single, readable formula. Nevertheless, LEFT, RIGHT, and MID remain the most widely compatible approach across all Excel versions.

Frequently Asked Questions

  • What is the difference between LEFT, RIGHT, and MID in Excel?+
    LEFT extracts a set number of characters from the beginning of a text string. RIGHT extracts from the end. MID extracts from any position in the middle — you specify the start position and the number of characters. Together, the three functions cover every part of a string. All three return text, even if the extracted characters look like numbers.
  • How do I extract text before a specific character?+
    Use LEFT combined with FIND. FIND returns the position of the delimiter, and LEFT takes everything before it: =LEFT(A2, FIND("-",A2)-1). The minus 1 excludes the delimiter itself. If the delimiter might be missing from some rows, wrap the formula in IFERROR to prevent #VALUE! errors.
  • How do I extract text after a specific character?+
    Use RIGHT combined with LEN and FIND: =RIGHT(A2, LEN(A2) - FIND("-",A2)). This calculates the total string length, subtracts the position of the delimiter, and extracts the remaining characters. The result excludes the delimiter itself. Change "-" to any other character to suit your data.

More Questions About Text Extraction

  • What is the difference between FIND and SEARCH?+
    FIND is case-sensitive — it distinguishes between uppercase and lowercase letters. SEARCH is case-insensitive. For delimiter-based extraction, it makes no practical difference. However, when you search for a specific word or letter where case matters, use FIND. Additionally, SEARCH supports wildcard characters (? and *) while FIND does not.
  • Do LEFT, RIGHT, and MID return numbers or text?+
    All three functions always return text, even when the extracted characters are digits. Consequently, you cannot use the result directly in arithmetic without first converting it. To convert text to a number, wrap the formula in VALUE: =VALUE(RIGHT(A2,4)). Alternatively, multiply by 1 or add 0 to trigger an automatic conversion.
  • Which Excel versions support LEFT, RIGHT, and MID?+
    All three functions have been available since Excel 2000 and work in every version up to Microsoft 365. They also work in Excel for the web and Google Sheets. No special version, add-in, or setting is required. This makes them the most universally compatible text-extraction tools in Excel.