How to extract the middle name from a full name in Excel
Excel formula
=TEXTBEFORE(TEXTAFTER(A2," ")," ",-1,,,"")Take the text between the first and the last space: =TEXTBEFORE(TEXTAFTER(A2," ")," ",-1,,,""). Names without a middle name return blank.
- Result on the example
- one result per row in
B2, filled down toB8 - Works in
- Microsoft 365 only
- Google Sheets
- Different formula, see below
See it work
The formula is already in B2, filled down to B8. Change any input and the result updates, or edit the formula to experiment.
How it works
TEXTAFTER drops the first name, leaving "Ann Smith". TEXTBEFORE with -1 then keeps everything before the last space, which drops the last name. When there is no middle name, the inner result has no space left, so TEXTBEFORE uses its sixth argument and returns "" instead of #N/A.
=TEXTBEFORE(TEXTAFTER(A2," ")," ",-1,,,"")Result"Ann"
A2"Mary Ann Smith"The value in A2.
TEXTAFTER(A2," ")"Ann Smith"TEXTAFTER: Text after a delimiter.- text
A2"Mary Ann Smith" - delimiter
" "
- text
-1-1Makes the value negative.
TEXTBEFORE(TEXTAFTER(A2," ")," ",-1,,,"")"Ann"TEXTBEFORE: Text before a delimiter.- text
TEXTAFTER(A2," ")"Ann Smith" - delimiter
" " - instance_num
-1-1 - match_mode
(omitted) - match_end
(omitted) - if_not_found
""
- text
In Google Sheets
Google Sheets needs a different formula: =IFERROR(REGEXEXTRACT(A2,"^\S+ (.+) \S+$"),""). On the same data it gives the same result. Here it is running in Google Sheets mode.
Other ways to do it
Each one was run on the same example sheet.
| Formula | Result | When to use it |
|---|---|---|
| =IFERROR(MID(A2,FIND(" ",A2)+1,FIND(" ",A2,FIND(" ",A2)+1)-FIND(" ",A2)-1),"") | Ann, , Paul… | Works in every version: MID takes the characters between the first and second space. With two middle names it returns only the first one. |
Common mistakes
- Extra spaces shift every position. Wrap the name in TRIM first.
- Suffixes like "Jr." are treated as the last name, so "John Paul Jones Jr." returns "Paul Jones".
- Without the sixth argument, TEXTBEFORE returns #N/A for every two-part name.
Try it yourself
Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.
Extract the middle name from a full name
B2, extract the middle name (the text between the first and last names) and fill down to B8. Leave it blank when there is no middle name.Questions
How do I get only the middle initial?
Take the first letter of the result: =LEFT(TEXTBEFORE(TEXTAFTER(A2," ")," ",-1,,,""),1).
How do I remove the middle name instead?
Join the first and last names: =TEXTBEFORE(A2," ")&" "&TEXTAFTER(A2," ",-1).
Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.