Excelparsing单元格值

我在单元格A1中放置了以下内容:

"a lot of text marker: xxx some more text"

我想将xxx值复制到单元格A2

任何build议如何做到这一点?

谢谢

 =MID(A1, FIND("marker:",A1) + LEN("marker:"), 4) 

我假设xxx(按照你的例子)是3个字符长,在“marker:”和“xxx”之间有一个空格。

只是我的两分钱。 Find()是区分大小写的,所以如果A1中的文本是

“很多文字标记:xxx多一些文字”

然后Find会给你一个错误。

你可以使用Search()来代替FIND()

= MID(A1,SEARCH(“marker:”,A1)+ LEN(“marker:”),3)

还取决于您的区域设置,您可能必须使用“;” 代替 ”,”

如果你想要一个VBA的解决scheme,这对我使用你的示例input:

 Function GetValue(rng As Excel.Range) As String Dim tempValue As String Dim arrValues() As String ' get value from source range tempValue = rng.value ' split by ":" character arrValues = Split(tempValue, ":") ' split by spaces and take the second array element ' because there is a space between ":" and "xxx" GetXXXValue = Trim$(Split(arrValues(1), " ")(1)) End Function 

要使用,请将此代码放入工作表模块中(请参阅我在何处粘贴要在工作簿中使用的代码以获取位置帮助),然后将以下内容放入单元格A2:

=GetValue(A1)