vba 在excel单元格中提取字符串的一部分
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17815469/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Extract part of a string in excel cell
提问by asim-ishaq
I have an excel spreadsheet in which there is a column containing a specific string. I need to extract part of that string in another column.
我有一个 Excel 电子表格,其中有一列包含特定字符串。我需要在另一列中提取该字符串的一部分。
The data is as follows:
数据如下:
Column A
---------------------------------
FIS/SIFT/SBG091241012FIS/SIFT/SBG091241012
FIS/SIFT/SBG091311212FIS/SIFT/SBG09111212
..
...
Is there any formula in excel through which i can extract the last part of string after forward slash (/). In the above example these are:
excel中是否有任何公式可以通过它我可以在正斜杠(/)之后提取字符串的最后一部分。在上面的例子中,这些是:
SBG091241012
SBG09111212
Please note that the last part of string after slash (/) is variable length so we may not be able to use the =RIGHTfunction in excel.
请注意,斜线 (/) 后面的字符串的最后一部分是可变长度的,因此我们可能无法在 Excel 中使用=RIGHT函数。
回答by matzone
Use this function ..
使用这个功能..
Function GetTail(r As Range) As String
Dim s As String
s = r.Value
GetTail = Mid(s, InStrRev(s, "/") + 1)
End Function
回答by Kamal G
Though the above answer is perfect. But in case you like Right function for any reason:
虽然上面的答案是完美的。但如果您出于任何原因喜欢 Right 函数:
Right(str, Len(str) - InStrRev(str, "/", -1, vbTextCompare))
Right(str, Len(str) - InStrRev(str, "/", -1, vbTextCompare))