Excel LEFT, RIGHT, MID: Extract Text by Position
Pull characters from the start, end, or middle of text. Essential for parsing product codes, IDs, and fixed-format data.
Formula Genius can generate a draft from a plain-English prompt. Supported formulas can be checked with sample cases; review the coverage on the result.
The formula
"Extract the year, month, and day from an 8-digit date code like 20260215"
=LEFT(A2, 4) & "-" & MID(A2, 5, 2) & "-" & RIGHT(A2, 2)
LEFT(A2, 4) grabs the first 4 characters (year). MID(A2, 5, 2) grabs 2 characters starting at position 5 (month). RIGHT(A2, 2) grabs the last 2 characters (day). Ampersands join them with dashes.
Step-by-step breakdown
- LEFT(text, num_chars) returns characters from the start
- MID(text, start_num, num_chars) returns characters from any position
- RIGHT(text, num_chars) returns characters from the end
- & concatenates the pieces with dash separators
- Result: '20260215' becomes '2026-02-15'
Edge cases & warnings
- If num_chars exceeds the text length, the full text is returned (no error)
- MID with start_num beyond text length returns empty string
- These functions count characters, not bytes — emoji and accented characters count as 1
- For dynamic extraction, combine with FIND or SEARCH to locate delimiters
Examples
"20260215"
2026-02-15
"=LEFT("Hello World", 5)"
Hello
"=MID("ABCDEF", 3, 2)"
CD
Frequently asked questions
How do I extract text before a specific character?
Use LEFT with FIND: =LEFT(A2, FIND("-", A2)-1) extracts everything before the first dash.
What if the position varies?
Combine with FIND or SEARCH to locate characters dynamically. Example: =MID(A2, FIND("@", A2)+1, 100) extracts text after the @ sign.
Can't find what you need?
Describe a formula in plain English. Formula Genius drafts and explains it, and can check supported formulas on sample cases.