2

在 Excel 2010 中,使用 VBA,找到某个字符时如何拆分字符串?

假设A1="This is a | test of | the | emergency broadcast signal" 我将其分配给一个变量,例如

strColumnA = Range("A" & CStr(currRow)).Value

现在我想在工作表 2 的末尾追加 4 个新行。所有 A 列,如:

A1 = "This is a"
A2 = "test of"
A3 = "the"
A4 = "emergency broadcast signal"

有任何想法吗?

4

2 回答 2

1

使用它,因为不需要循环,离开Application.Trim()in 也很重要:

Sub test()

    Dim r As Variant, s As String
    s = [a1].Value
    r = Split(Application.Trim(s), "|")

    [b1].Resize(UBound(r, 1) + 1) = Application.Transpose(r)

End Sub
于 2013-04-19T08:57:59.967 回答
0

利用Split()

Sub Sample()
    Dim Ret
    Dim strColumnA As String
    Dim i As Long

    strColumnA = "This is a | test of | the | emergency broadcast signal"
    Ret = Split(strColumnA, "|")

    For i = LBound(Ret) To UBound(Ret)
        Debug.Print Ret(i)
    Next i
End Sub
于 2013-04-19T07:41:05.543 回答