How can I use Excel to find the last occurrence of a specific character in a string? 2

How can I use Excel to find the last occurrence of a specific character in a string?

Excel is a powerful tool that can be utilized to efficiently find the last occurrence of a specific character in a string. By using the FIND function in Excel, users can easily locate the position of the last occurrence of a particular character within a string. This function allows for precise and accurate identification of the desired character, saving time and effort in navigating through lengthy strings of data. By simply inputting the character and string into the FIND function, Excel will provide the position of the last occurrence, streamlining the process of data analysis and manipulation. This feature is particularly useful for organizing and managing large sets of data, making Excel a valuable resource for data analysis and management.

Excel: Find Last Occurrence of Character in String


You can use the following formula in Excel to find the last occurrence of a specific character in a string:

=LEN(TEXTBEFORE(A2,"/",-1))+1

This particular formula finds the position of the last occurrence of a slash ( / ) in cell A2.

The following example shows how to use this formula in practice.

Example: Find Last Occurrence of Character in String in Excel

Suppose we have the following column of phrases in Excel:

Suppose we would like to find the position of the last occurrence of a slash ( / ) in each cell in column A.

We can type the following formula into cell B2 to do so:

=LEN(TEXTBEFORE(A2,"/",-1))+1

We can then click and drag this formula down to each remaining cell in column B:

Column B now contains the position of the last occurrence of a slash ( / ) in each cell in column A.

For example, consider the first string in cell A2:

  • this/is/a/string

The position of the last occurrence of a slash in this string is in position 10:

  • this/is/a/string

How This Formula Works

Recall the formula that we used to find the position of the last occurrence of a slash in cell A2:

=LEN(TEXTBEFORE(A2,"/",-1))+1

This formula uses the TEXTBEFORE function, which uses the following basic syntax:

TEXTBEFORE(text, delimiter, [instance_num], …)

where:

  • text: Text to search
  • delimiter: Character or substring to extract text before
  • instance_num: Instance of delimiter before which to extract text (default is 1)

By using TEXTBEFORE(A2, “/”,-1) we are able to extract the following text:

  • this/is/a

Then we use the LEN function to get the length of this text, which returns 9.

Lastly, we add one to get 10.

This represents the position of the last occurrence of a slash in cell A2.

Note: You can find the complete documentation for the TEXTBEFORE function in Excel .

The following tutorials explain how to perform other common tasks in Excel:

Cite this article

stats writer (2024). How can I use Excel to find the last occurrence of a specific character in a string?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-use-excel-to-find-the-last-occurrence-of-a-specific-character-in-a-string/

stats writer. "How can I use Excel to find the last occurrence of a specific character in a string?." PSYCHOLOGICAL SCALES, 22 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-use-excel-to-find-the-last-occurrence-of-a-specific-character-in-a-string/.

stats writer. "How can I use Excel to find the last occurrence of a specific character in a string?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-use-excel-to-find-the-last-occurrence-of-a-specific-character-in-a-string/.

stats writer (2024) 'How can I use Excel to find the last occurrence of a specific character in a string?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-use-excel-to-find-the-last-occurrence-of-a-specific-character-in-a-string/.

[1] stats writer, "How can I use Excel to find the last occurrence of a specific character in a string?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.

stats writer. How can I use Excel to find the last occurrence of a specific character in a string?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top