在最后一个反斜杠之后提取剩余string的函数

我需要一个Excel函数,可以从path中提取最后一个string,如果没有find,然后采取整个string。 例如:

 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.将所有“\”更改为空格,空格的数量由单元格中的字符数决定

2.使用正确的function根据单元格中的字符数来提取string的右侧。

3.使用修剪function删除空格。

在这里输入图像说明

你的结果将是。

在这里输入图像说明

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

正如所build议的,没有公式或vba做到这一点的一种方法是使用“查找/replace”。 按Ctrl和“H”键,然后执行以下操作。

find什么* \,并用什么来replace

在这里输入图像描述

VBA的代码将是

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