Find the Position of the Last Slash in an Excel Text String
Question details
Find the position of the final slash in a text string using a spreadsheet formula.

- 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.
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 (|).
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.
Click an empty cell next to the text in A1, such as B1.
Type =IFERROR(FIND("|",SUBSTITUTE(A1,"/","|",LEN(A1)-LEN(SUBSTITUTE(A1,"/","")))),"") and press Enter.
Drag the fill handle from B1 down to calculate positions for the text in other rows.

Use TEXTBEFORE in Excel for Microsoft 365
Use a shorter formula when the text is guaranteed to contain a slash.
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. Open your spreadsheet: Open WPS Spreadsheets and select the workbook containing your text.
- 2. Select a result cell: Click an empty cell, such as B1, next to the text in A1.
- 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. Fill additional rows: Drag the fill handle down from the formula cell to calculate results for other rows.

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.




