ExcelReady
CourseMock testsFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before day one. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Mock tests
  • Function guides
  • Blog

Test prep

  • Excel level test
  • Excel test practice
  • Free screening quiz
  • Certificate

Company

  • About
  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Text
  3. Find the Nth Occurrence of a Character in Excel

Find the Nth Occurrence of a Character in Excel

By ExcelReady Team·Updated November 2, 2026·7 min read

The short answer

FIND only returns the first match, so swap the nth character for a unique marker and find that: =FIND("#",SUBSTITUTE(A2,"-","#",2)) gives the position of the second dash. In Microsoft 365 or Excel 2024, TEXTBEFORE and TEXTAFTER take an instance number, so =TEXTAFTER(A2,"-",2) returns the text after the second dash directly.

Key takeaways

  • SUBSTITUTE's fourth argument replaces only one occurrence, which lets FIND locate the nth character.
  • The pattern is =FIND("#",SUBSTITUTE(text,char,"#",n)). Use CHAR(1) as the marker if the text could contain #.
  • Wrap the position in LEFT or MID to get the text before or after the nth character.
  • TEXTBEFORE and TEXTAFTER accept an instance number, and -1 means the last one.
  • If there are fewer than n matches, FIND returns #VALUE! and TEXTAFTER returns #N/A.
On this page+
  1. Why FIND alone only finds the first one
  2. How to find the nth occurrence with FIND and SUBSTITUTE
  3. How to get the text before or after the nth character
  4. The easier way: TEXTBEFORE and TEXTAFTER
  5. How to find the last occurrence
  6. Example: get the folder from a file path
  7. Why the formula returns #VALUE! or the wrong position
  8. Practise it

To find the nth occurrence of a character in Excel, replace just that occurrence with a marker and then FIND the marker: =FIND("#",SUBSTITUTE(A2,"-","#",2)) returns the position of the second dash. In Microsoft 365 or Excel 2024, TEXTBEFORE and TEXTAFTER can skip straight to the text around the nth character. This guide is for anyone splitting codes, file paths or IDs that have the same separator more than once.

Why FIND alone only finds the first one#

FIND returns the position of the first match it sees. In the code NY-2024-INV-0087, =FIND("-",A2) returns 3, and there is no argument for "the second one". FIND does have an optional start position, so you can nest it:

Excel formula
=FIND("-",A2,FIND("-",A2)+1)

The inner FIND finds the first dash (3), and the outer FIND starts looking at character 4. The result is 8. This works for the second match, but it gets long fast: the third match needs three FINDs. The FIND function guide covers the start position, and the article on FIND vs SEARCH explains which one ignores capitals.

How to find the nth occurrence with FIND and SUBSTITUTE#

SUBSTITUTE has an optional fourth argument, instance_num, that replaces only one occurrence. That is the key to the whole trick:

Excel formula
=FIND("#",SUBSTITUTE(A2,"-","#",2))

Read it from the inside out:

  1. SUBSTITUTE(A2,"-","#",2) changes only the second dash, so NY-2024-INV-0087 becomes NY-2024#INV-0087.
  2. FIND("#", ...) returns the position of the only #, which is 8.

Change the 2 to any number to find any occurrence. Better still, point it at a cell so one formula handles every row:

ABC
1CodeDash numberPosition
2NY-2024-INV-008728
3LA-2023-CRN-1140312
4TX-2025-INV-001213

In C2: =FIND("#",SUBSTITUTE(A2,"-","#",B2)), then fill down (Windows: Ctrl+D; Mac: ⌘D).

The marker must be a character that never appears in your text. If # might be in the data, use CHAR(1), an invisible control character: =FIND(CHAR(1),SUBSTITUTE(A2,"-",CHAR(1),B2)). The SUBSTITUTE function guide and the article on SUBSTITUTE vs REPLACE explain the other arguments.

How to get the text before or after the nth character#

A position on its own is rarely the goal. You usually want the text on one side of it. Wrap the position in LEFT or MID.

Text before the second dash (everything left of position 8):

Excel formula
=LEFT(A2,FIND("#",SUBSTITUTE(A2,"-","#",2))-1)

Result: NY-2024. The -1 drops the dash itself.

Text after the second dash (start one character after it):

Excel formula
=MID(A2,FIND("#",SUBSTITUTE(A2,"-","#",2))+1,LEN(A2))

Result: INV-0087. Using LEN(A2) as the length simply means "take the rest"; MID stops at the end of the text.

Text between the second and third dash needs both positions: the start is after dash 2, and the length is the gap to dash 3.

Excel formula
=MID(A2,FIND("#",SUBSTITUTE(A2,"-","#",2))+1,FIND("#",SUBSTITUTE(A2,"-","#",3))-FIND("#",SUBSTITUTE(A2,"-","#",2))-1)

Result: INV. It works, but it is long. The guide to extracting text between two characters shows shorter ways.

The easier way: TEXTBEFORE and TEXTAFTER#

If you have Microsoft 365 or Excel 2024, TEXTBEFORE and TEXTAFTER do all of this in one step. Their third argument is the instance number:

GoalFormulaResult
Text before the 2nd dash=TEXTBEFORE(A2,"-",2)NY-2024
Text after the 2nd dash=TEXTAFTER(A2,"-",2)INV-0087
Text before the 3rd dash=TEXTBEFORE(A2,"-",3)NY-2024-INV
Text after the last dash=TEXTAFTER(A2,"-",-1)0087
Text between dash 2 and 3=TEXTBEFORE(TEXTAFTER(A2,"-",2),"-")INV

A negative instance number counts from the end, so -1 means the last occurrence. That makes file paths easy: if A6 holds C:\Reports\2024\June\sales.xlsx, =TEXTAFTER(A6,"\",-1) returns sales.xlsx. The full guide to TEXTBEFORE and TEXTAFTER covers the other arguments, such as ignoring case.

Older Excel versions show #NAME? for these functions. If your file must open in Excel 2019 or earlier, stick with FIND and SUBSTITUTE.

How to find the last occurrence#

The last occurrence is just the nth one, where n is the number of times the character appears. Count it by comparing the length with and without that character:

Excel formula
=LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))

For NY-2024-INV-0087 that is 16 − 13 = 3 dashes. Use the count as the instance number:

Excel formula
=FIND("#",SUBSTITUTE(A2,"-","#",LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))))

The result is 12, the position of the last dash. The same idea helps when you need the last word in a cell, where the separator is a space.

Example: get the folder from a file path#

File paths are a common real case, because the backslash appears many times. Say A6 holds C:\Reports\2024\June\sales.xlsx and you want everything up to the third backslash, the year folder:

Excel formula
=LEFT(A6,FIND("#",SUBSTITUTE(A6,"\","#",3))-1)

The third backslash is at position 16, so LEFT keeps 15 characters: C:\Reports\2024. In Microsoft 365 or Excel 2024, =TEXTBEFORE(A6,"\",3) gives the same result, and =TEXTBEFORE(A6,"\",-1) returns the whole folder path without the file name. The same pattern works for web addresses split by /, product codes split by ., and log lines split by |. Only the character inside the quotes changes.

Why the formula returns #VALUE! or the wrong position#

Most problems come from three causes:

  • Fewer matches than n. If a code has only two dashes and you ask for the third, SUBSTITUTE changes nothing and FIND returns #VALUE!. Wrap it: =IFERROR(FIND("#",SUBSTITUTE(A2,"-","#",3)),"Not found"). TEXTAFTER returns #N/A instead, and its sixth argument sets a message, for example =TEXTAFTER(A2,"-",3,,,"none").
  • Case. FIND and SUBSTITUTE are both case-sensitive. To find the second "x" in "Xbox max", wrap the text in LOWER: SUBSTITUTE(LOWER(A2),"x","#",2).
  • Hidden spaces. A leading space shifts every position by one. Clean the column with TRIM first if the numbers look off by one.

Practise it#

The FIND and SUBSTITUTE pattern feels odd until you have typed it a few times. Practise FIND and SEARCH in a live spreadsheet: you'll locate characters and pull text out with LEFT and MID, and each answer is checked instantly. Then open the TEXTBEFORE and TEXTAFTER lesson to split text by the nth separator in one step. Start with the exercise on this page.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

Find the position of the second dash in the code in A2. In C2, use SUBSTITUTE to swap dash number B2 for #, then FIND the #.

fx
ABCD
1
Code
Dash number
Position
2
NY-2024-INV-0087
2
3
LA-2023-CRN-1140
3
4
TX-2025-INV-0012
1
5
6
7

Tip: SUBSTITUTE(A2,"-","#",B2) changes only the dash number in B2. Put that inside FIND("#", ...).

Practise this in a lesson

LessonFIND and SEARCHLocate a character or word inside text with FIND or SEARCH, then use that position to split names and pull out order numbers.LessonTEXTBEFORE and TEXTAFTERSplit emails, "Last, First" names and file paths at a delimiter with TEXTBEFORE and TEXTAFTER, including picking which occurrence to split at.Function guideFINDLocate a character inside text with Excel's FIND, then use it with LEFT, MID and RIGHT. Case rules, #VALUE! fixes and a live exercise.Function guideSUBSTITUTESwap or strip characters with Excel's SUBSTITUTE: clean phone numbers, change one occurrence and count characters with LEN. Practice it live.

Frequently asked questions

How do I find the second occurrence of a character in Excel?

+

Use =FIND("#",SUBSTITUTE(A2,"-","#",2)). SUBSTITUTE changes only the second dash into #, and FIND returns its position. For a short case you can also nest FIND: =FIND("-",A2,FIND("-",A2)+1).

How do I find the last occurrence of a character in Excel?

+

Count the characters with LEN(A2)-LEN(SUBSTITUTE(A2,"-","")) and use that count as the instance number in SUBSTITUTE. In Microsoft 365 or Excel 2024, =TEXTAFTER(A2,"-",-1) returns the text after the last dash.

Why does my nth occurrence formula return #VALUE!?

+

The text has fewer than n of that character, so SUBSTITUTE changes nothing and FIND can't find the marker. Wrap the formula in IFERROR to show a message instead.

Is the nth occurrence formula case-sensitive?

+

Yes. Both FIND and SUBSTITUTE match capitals exactly. For letters, wrap the text in LOWER first, for example SUBSTITUTE(LOWER(A2),"x","#",2).

Sources

  • FIND, FINDB functions - Microsoft Support
  • SUBSTITUTE function - Microsoft Support
  • TEXTAFTER function - Microsoft Support

Written and checked by the ExcelReady Team. First published November 2, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. Why FIND alone only finds the first one
  2. How to find the nth occurrence with FIND and SUBSTITUTE
  3. How to get the text before or after the nth character
  4. The easier way: TEXTBEFORE and TEXTAFTER
  5. How to find the last occurrence
  6. Example: get the folder from a file path
  7. Why the formula returns #VALUE! or the wrong position
  8. Practise it

Keep reading

Text· 7 min read

Find the Position of Text in a Cell (FIND and SEARCH)

FIND and SEARCH return the position of some text inside a cell, as a number. =FIND(" ",A2) gives 5 for Dana Whitfield, because the space is the 5th character. FIND is case-sensitive; SEARCH ignores capitals and allows wildcards. Both return #VALUE! when the text isn't there, so wrap them in ISNUMBER to test whether a cell contains a word.

Text· 8 min read

SUBSTITUTE and REPLACE in Excel

Use SUBSTITUTE when you know the text you want to change: =SUBSTITUTE(A2,".","-") swaps every dot for a dash. Use REPLACE when you know the position: =REPLACE(A2,1,3,"XXX") overwrites the first three characters. SUBSTITUTE is case-sensitive and can change just one occurrence; REPLACE ignores what the characters say.

Text· 7 min read

Extract the Last Word From a Cell in Excel

To extract the last word from a cell in Microsoft 365 or Excel 2024, use =TEXTAFTER(A2," ",-1). The -1 tells Excel to start from the last space instead of the first. In older versions, use =TRIM(RIGHT(SUBSTITUTE(A2," ",REPT(" ",100)),100)), which works for any number of words.

More on text

  • How to Format Phone Numbers in Excel
  • How to Create a Unique ID in Excel With a Formula
  • Get Initials From a Name in Excel
  • How to Add or Keep Leading Zeros in Excel
  • LEFT, RIGHT and MID in Excel: Pull Out Part of a Cell
  • Line Breaks in Excel: In a Cell and in a Formula
All text articles →

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback, right in your browser. Nothing to download.

Start learning for free