How to find nth occurrence (position) of a character in text string in Excel?

For example, there is a long sentence in Cell A1, see the following screenshot. And now you need to find the 3rd occurrence or position of Character "c" from the text string in Cell A1. Of course, you can count the characters one by one, and get the exact position result. However, here we are going to introduce some easy tips to find the nth occurrence or position of specific character from text string in a cell.


Count times a word(count times of a specific word appears in a single cell or a range .)

doc formula 1

arrow blue right bubble Find nth occurrence (position) of a character in a Cell with Find formula


There are two Find formulas can help you find the nth occurrence or position of specific character from text string in a cells quickly.

The following formula will show you how to find the 3rd occurrence of "c" in Cell A1.

Kutools for Excel, with more than 120 handy Excel functions, enhance your working efficiency and save your working time.

Find Formula 1

In a blank cell, enter the formula =FIND("c",A1,FIND("c",A1)+2).

doc-find-nth-position-of-text-string2

And then press the Enter key. The position of the third letter “c” has been displayed.

Note: You can change the 2 in the formula based on your needs. For example, if you want to find the fourth position of "c", you can change the 2 to 3. And if you want to find the first position of "c", you shuold change 2 to 0.

Find formula 2

In a blank cell, enter the formula =FIND(CHAR(1),SUBSTITUTE(A1,"c",CHAR(1),3)), and press Enter key.

Note: The "3" in the formula means the third "c", you can change it based on your needs.


arrow blue right bubble Find nth occurrence (position) of a character in a Cell with VBA

Actually, you can apply the VB macro to find nth occurrence or position of a specific character in one cell easily.

Kutools for Excel, with more than 120 handy Excel functions, enhance your working efficiency and save your working time.

Step 1: Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

Step 2: Click Insert > Module, and paste the following macro in the Module Window.

VBA: Find the nth position of a charater.

Function FindN(sFindWhat As String, _
sInputString As String, N As Integer) As Integer
Dim J As Integer
Application.Volatile
FindN = 0
For J = 1 To N
FindN = InStr(FindN + 1, sInputString, sFindWhat)
If FindN = 0 Then Exit For
Next
End Function

Step 3: Now if you want find the exact occurrence of position of third "c" in Cell A1, please enter the formula of =FindN("c",A1,3), and press the Enter key. Then it will return the exact position in the specific cell at once.


arrow blue right bubble Find nth occurrence (position) of a character in a Cell with Kutools for Excel

If you like neither of formula and VBA, you can try a handy tool – Kutools for Excel, with its Formula groups, you can find a utility – Find nth occurrence of a character to quickly return the nth position of a character in a cell.

Kutools for Excel, with more than 120 handy Excel functions, enhance your working efficiency and save your working time.

After free installing Kutools for Excel, please do as below:

1. Select a cell you want to return the result and click Kutools > Formulas > Find nth occurrence of a character. See screenshot:

doc kutools 1

2. Then in the popping Formula Helper dialog, do as below:

doc find position of text string 4
1) Select the cell you want to find out a specific character from to the String textbox;



2) Type the character you want to find around with double quotations “” into Character textbox;



3) Type the nth occurrence of character into Nth occurrence textbox.

3. Click Ok. And you get the position of nth occurrence of a character in a string.

doc find position of text string 5

pay attention1If you are interested in this addi-in, download the 60-days free trial.

Count Weekdays/Weekends/Specific Weekday between two dates 

Supposing you have a two given dates, one is start date and another is end date, how can you quickly count the workday, weekend or a specific weekday such as Monday between thses date range? If you are interesed, you can try on Kutools for Excel's Count weekdays/weekends/specific weekday utilities.
doc count weekday weekend

Recommended Productivity Tools

Office Tab

gold star1 Bring handy tabs to Excel and other Office software, just like Chrome, Firefox and new Internet Explorer.

Kutools for Excel

gold star1 Amazing! Increase your productivity in 5 minutes. Don't need any special skills, save two hours every day!

gold star1 200 New Features for Excel, Make Excel Much Easy and Powerful:

  • Merge Cell/Rows/Columns without Losing Data.
  • Combine and Consolidate Multiple Sheets and Workbooks.
  • Compare Ranges, Copy Multiple Ranges, Convert Text to Date, Unit and Currency Conversion.
  • Count by Colors, Paging Subtotals, Advanced Sort and Super Filter,
  • More Select/Insert/Delete/Text/Format/Link/Comment/Workbooks/Worksheets Tools...

Screen shot of Kutools for Excel

btn read more      btn download     btn purchase

Comments  

Permalink +10 DdW
Find Formula 1 won't work. The third parameter of the Find function is the index where the search should begin (as in: the first x characters of the string are ignored). i.e. if a string contains the letter c at indices 1, 5 and 10 the results are as follows:
=FIND("c",A1,1) will find the first c
=FIND("c",A1,2) through =FIND("c",A1,5) will find the second c
=FIND("c",A1,6) through =FIND("c",A1,10 ) will find the third c.
anything above won't find anything.
2013-10-22 14:42 Reply Reply with quote Quote
Permalink -11 skyyang
Thank you for finding out this mistake, i'm sorry the formula1 is wrong, the correct formula should be =FIND("c",A1,FI ND("c",A1)+2) ,and if you want to find the first letter "c", you just need to change the 2 to 0.
2013-10-24 06:53 Reply Reply with quote Quote
Permalink +3 Matthew
As DdW indicates, the '+2' or '+0' or what-have-you is a 'hard-coded' character position; you'd have to already know where the "c" was, in order to find it.

Formula 2 is spot-on, though: SUBSTITUTE the nth instance of your target string for a unique character that won't otherwise appear in the rest of the text, then FIND that unique character.
2013-11-20 22:21 Reply Reply with quote Quote
Permalink 0 sanjeev
I am able to find second instance but what about 3rd, 4th and 'n'th. I am not able to get 3rd instance (as well as 4th). I have data which contains 50 to 60 instances. so what should I do?
2016-01-21 14:09 Reply Reply with quote Quote
Permalink +1 Matthew
sanjeev, as I said two years ago, use Formula 2:

=FIND(CHAR(1),SUBSTITUTE("LOOK_IN","LOOK_FOR",CHAR(1),INST_NUM))

Where LOOK_IN is the string (or cell) you're searching in;
LOOK_FOR is the string you're searching for; and
INST_NUM is the integer instance of LOOK_FOR that you want to identify.

Hence, =FIND(CHAR(1),S UBSTITUTE("HELL O WORLD","L",CHAR (1),3) will return 10 (the position of the third "L").
2016-02-05 11:09 Reply Reply with quote Quote
Permalink -4 Mohit Sharma
Dear All,

I want to select a particulate string form a cell
Example:-

My Name is Mohit

i want to return any value Like mohit, is, Name, My using a function.
is there any Function or not
2013-11-14 06:32 Reply Reply with quote Quote
Permalink 0 DdW
I think there is no specific function for that, since Excel is not built to handle lists of values in one cell. You can build the function yourself by combining the functions mentioned above with LEFT() and RIGHT(). Or you could use VBscripting of course.
2013-11-18 05:37 Reply Reply with quote Quote
Permalink -2 Geep
After some playing around I got the following to find the third instance of X and return the position number.

=FIND("X",A1,(FIND("X",A1,FIND("X",A1,1)+1))+1)

The VBA module gets my vote though. Much easier to remember
2014-03-28 09:43 Reply Reply with quote Quote
Permalink +1 Matthew
Sure, but you could nest formulae in the "instance number" parameter indefinitely. Formula 2 obviates VBA, making it the best all-round solution.
2014-03-31 01:24 Reply Reply with quote Quote
Permalink -3 jr
Try this:
=INDEX(SMALL(IF(MID(A1,MATCH(ROW(INDIRECT(1&":"&LEN(A1))),ROW(INDIRECT(1&":"&LEN(A1))),0),1)="c",MATCH(ROW(INDIRECT(1&":"&LEN(A1))),ROW(INDIRECT(1&":"&LEN(A1))),0),""),MATCH(ROW(INDIRECT(1&":"&LEN(A1)-LEN(SUBSTITUTE(A1,"c","")))),ROW(INDIRECT(1&":"&LEN(A1)-LEN(SUBSTITUTE(A1,"c","")))),0)),2)
where "c" is the character required and 2 is the position. Note this is an array formula.
2015-01-10 05:43 Reply Reply with quote Quote
Permalink -3 jr
this is simpler:
=INDEX(SMALL(IF(MID(A1,ROW(INDIRECT(1&":"&LEN(A1))),1)="c",ROW(INDIRECT(1&":"&LEN(A1))),""),ROW(INDIRECT(1&":"&LEN(A1)-LEN(SUBSTITUTE(A1,"c",""))))),2)
2015-04-23 12:46 Reply Reply with quote Quote
Permalink 0 Philip Oyetunde
Hello all,

I have a text in an Excel cell "23 floyd lane, longville,KN 14564"

I need a function to extract just "longville"

Thanks
2016-09-27 13:19 Reply Reply with quote Quote
Permalink 0 Rukt
If you must use a function, try: =TRIM(MID(A1,SEARCH(",",A1)+1,SEARCH("!@#",SUBSTITUTE(A1,",","!@#",2))-SEARCH(",",A1)-1))

Otherwise, you might consider Data > Text to Columns > Delimited (using a comma as the separator).
2016-09-29 02:34 Reply Reply with quote Quote

Add comment


Security code
Refresh