在最后一个反斜杠后提取剩余字符串的函数

Function to extract remaining string after last backslash

我需要一个 Excel 函数,它可以从路径中最后一个 \ 之后提取字符串,如果没有找到 \ 则获取整个字符串。例如:

D:\testing\rbc.xls                     output will be   rbc.xls
D:\home\testing\test1\script1.sql      output will be   script.sql
script 3.txt                           output will be   script 3.txt

1.Change所有“\”为空格,空格个数由单元格字符数决定

2.Use右边函数根据单元格中的字符数提取字符串的右边。

3.Usetrim函数去除空格。

你的结果会是。

=TRIM(RIGHT(SUBSTITUTE(A1,"\",REPT(" ",LEN(A1))),LEN(A1)))

如建议的那样,不使用公式或 vba 执行此操作的一种方法是使用 "Find/Replace"。 按 Ctrl 和 "H" 键并执行以下操作。

找到 *\ 并替换为空

VBA 代码为

Sub ReplaceIt()
    Columns("A").Replace What:="*\", Replacement:="", SearchOrder:=xlByColumns, MatchCase:=True
End Sub