31 Dec

How To Find Last Occurrence of Character in a String

There may be some instances where you will need to find the last occurrence of a specific character in a string in Excel. The following example shows you how.

Assuming that your original string is in cell B2 and the character that you want to find is “.” , the formula to give you the position of the last occurrence of the character in the string is:
=LEN(B2)-LEN(TRIM(RIGHT(SUBSTITUTE(B2,”.”,REPT(” “,LEN(B2))),LEN(B2))))

The following shows a breakdown of the above formula:

The key to this example is this magical formula, which gives you everything to the right of the last occurrence of the character “.”.
=TRIM(RIGHT(SUBSTITUTE(B2,”.”,REPT(” “,LEN(B2))),LEN(B2)))

Let me know if you need more explanation of the above. Thanks!