Excel Formula: Find position of nth occurrence of a character
To find the first occurrence of a character in a string in Excel, you can use the FIND function. However, how to find the position of the second or third or nth occurrence of a specific character in a string? Here this tutorial introduces a formula which combines the FIND and SUBSTITUTE functions to handle this task and explains the arguments of the formula.
|Text:the text or cell refence in which you want to find character.|
|Char:the character you want to find its position.|
|Nth_occurrence:the specified occurrence of the character.|
This formula returns a number which indicates the position of the nth occurrence of a character.
How this formula work
Here, in cell E3, you need to find the position of the second occurrence of the character in cell C2 in the text string in cell B3. Please use below formula:
Press Enter keys to get the position, and you can drag fill handle over the adjacent cells to apply this formula.
SUBSTITUTE(B3,C3,"~",D3): the SUBSTITUTE function replaces the old text with a new one in a specified instance. Here this formula replaces the character in cell C3 (+) with the new character “~” in the text string of cell B3 (Shift+Ctrl+Enter), and returns Shift+Ctrl~Enter.
FIND function: the FIND function returns the position of a character. Here the formula returns the position of character “~” in the new text string “Shift+Ctrl~Enter”.
“~” only indicates a new character which is used to replace the character you want to find, and you can change it to others. But take notice, it must be the character does not exist in the string.
- Find most requenst text with criteria
In some cases, you may want to find the text which appears most frequently based on a criterion in Excel. This tutorial introduces an array formula to handle this job and gives the explanation about the arguments of this formula.
- Combine cells with commas
Here this tutorial provides some formulas to join multiple cells into one cell with comma as separator as below screenshot shown, and also explains how the formulas work in Excel.
- Make text same length
If there is a list of texts with different lengths, for looking nicer, you can make these text with same length by adding trailing characters as below screenshot shown. Here it provides a formula which combines the LEN and REPT functions to handle it in Excel.
- Check if cell contains number
Sometimes, you may want to check if a cell contains numeric characters. This tutorial provides a formula which will return TRUE if the cell contains number, FALSE if cell does not contain number.