Excel文本公式,用于提取字段中以分号分隔的单词

sil*_*kid 3 excel excel-formula

Excel中的字段包含以分号分隔的单词,例如:

A1 =保存;国民;宝藏;因为;好

如何应用Excel文本公式在另一个字段中从此字段生成单独的单词?例如:

A2 should contain a formula to get the first word ("save")
A3 should contain a (different) formula to get the second word ("the")
etc.
Run Code Online (Sandbox Code Playgroud)

但是,即使A1中的值发生变化,这些公式也应保持良好状态,例如,如果A1的值更改为

A1 =你好;那里;怎么样;是;你

在这方面的任何帮助将受到高度赞赏.

(问题是我自己写的函数在这种情况下是不允许的,我必须使用原来的功能,如find,search,mid,等)

Rya*_*yan 5

您可以创建一个VBA函数来拆分此示例中的字段:

Function ExtractElement(str, n, sepChar)
'   Returns the nth element from a string,
'   using a specified separator character
    Dim x As Variant
    x = Split(str, sepChar)
    If n > 0 And n - 1 <= UBound(x) Then
       ExtractElement = x(n - 1)
    Else
        ExtractElement = ""
    End If
End Function
Run Code Online (Sandbox Code Playgroud)

那么A2公式将是:=ExtractElement(A1, 1, ";")并且A3将是:=ExtractElement(A1, 2, ";")依此类推