Function Problems

Find the Position of the Last Slash in an Excel Text String

Huda QurayshiHuda Qurayshi Nov 18, 2026 869 views

Question details

Find the position of the final slash in a text string using a spreadsheet formula.

Find the Position of the Last Slash in an Excel Text String
Product
Microsoft Excel
Device & OS
not provided
Scenario
A cell contains a file path, URL, or other text, and the user needs the position of its last slash.
Observed behavior
The formula should return the last slash's position, or a blank if the text has no slash.
Before you start

Place the text to check in a cell, such as A1, and choose an empty cell for the result. If you use the SUBSTITUTE formula below, check that the text does not already contain the pipe character (|).

Solution 1Recommended

Find the Last Slash with SUBSTITUTE and FIND

Use this formula to return the last slash's position or a blank when there is no slash.

The formula counts the slashes, replaces only the last one with a pipe character, and finds that marker. The returned position starts at 1.

1
Select a result cell

Click an empty cell next to the text in A1, such as B1.

2
Enter the formula

Type =IFERROR(FIND("|",SUBSTITUTE(A1,"/","|",LEN(A1)-LEN(SUBSTITUTE(A1,"/","")))),"") and press Enter.

3
Apply it to other rows

Drag the fill handle from B1 down to calculate positions for the text in other rows.

Find the Last Slash with SUBSTITUTE and FIND
Choose an unused marker: If the text can contain |, replace both instances of "|" in the formula with a character that does not appear in the text. Otherwise, FIND may return the position of an existing marker instead.
WPS Spreadsheets

Find the Last Slash Position in WPS Spreadsheets

Use a SUBSTITUTE and FIND formula in WPS Spreadsheets to locate the final slash in a file path or URL and return a blank when none exists.

  1. 1. Open your spreadsheet: Open WPS Spreadsheets and select the workbook containing your text.
  2. 2. Select a result cell: Click an empty cell, such as B1, next to the text in A1.
  3. 3. Enter the formula: Type =IFERROR(FIND("|",SUBSTITUTE(A1,"/","|",LEN(A1)-LEN(SUBSTITUTE(A1,"/","")))),"") and press Enter. Use a different marker if the text contains |.
  4. 4. Fill additional rows: Drag the fill handle down from the formula cell to calculate results for other rows.
Find the final slash without manually scanning long paths or URLsReturn a blank when the text has no slashOpen and edit Microsoft Excel XLSX and XLS filesApply the formula to multiple rows with the fill handle
microsoft office alternative - wps office

Frequently Asked Questions

What does the formula return if there is no slash?

The IFERROR formula returns a blank. Without IFERROR, the calculation can return an error when no slash is found.

Can I find the last backslash or another character instead?

Yes. Replace each "/" in the SUBSTITUTE formula with the character you want to find, such as "\" for a backslash. Keep the marker different from any character in the source text.

Why does the formula return the wrong position when my text contains a pipe?

FIND returns the first pipe it encounters, which may be an existing character rather than the replacement marker. Replace both instances of "|" in the formula with a character that does not appear in the text.

How do I use the formula for a different cell?

Replace each A1 reference in the formula with the cell containing your text. You can also drag the formula cell's fill handle down to adjust the references for other rows.