Excel解析单元格值

时间:2012-01-17 12:32:15

标签: excel parsing excel-vba vba

我已将以下内容放在单元格A1中:

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

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

有关如何做到这一点的任何建议?

由于

3 个答案:

答案 0 :(得分:2)

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

我假设xxx(根据您的示例)长度为3个字符,并且“marker:”和“xxx”之间存在空格。

答案 1 :(得分:1)

只是我的两分钱。如果A1中的文本是

,则Find()区分大小写

“很多文字标记:xxx更多文字”

然后,Find会给你一个错误。

您可以使用Search()代替FIND()

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

另外,根据您的区域设置,您可能需要使用“;”而不是“,”

答案 2 :(得分:0)

如果您想要一个VBA解决方案,这对我使用您的示例输入起作用:

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

要使用,请将此代码放入工作表模块(请参阅Where do I paste the code that I want to use in my workbook以获取展示位置帮助),然后将以下内容放入单元格A2中:

=GetValue(A1)

相关问题