无法使用两个参数来获得excel vba函数

时间:2017-08-10 23:47:46

标签: excel vba

我在Excel Vba中有这个功能:

Function split_std(cell As String, separator As String)

    Dim arr() As String
    arr() = Split(cell, separator)
    MsgBox (arr(0))

End Function

我这样称呼它:

Sub split_standard()
Set cell = Application.InputBox(Prompt:="Please select the cell to split", Title:="Cell Selection", Type:=8)
separator = InputBox("Please type in the separator of the items in the string")
Dim arr() As String


MsgBox (cell)

split_std (cell, separator)

End Sub

但是当完成对函数的调用时,错误:"预期:="出现。我已经尝试删除括号,但我无法使其工作。求救!

1 个答案:

答案 0 :(得分:1)

请改为尝试:

Function split_std(cell As String, separator As String)
    Dim arr() As String
    arr() = Split(cell, separator)
    MsgBox (arr(0))
End Function

Sub split_standard()
    Dim cell As String
    Dim separator As String

    cell = Application.InputBox(Prompt:="Please select the cell to split", Title:="Cell Selection", Type:=8)
    separator = InputBox("Please type in the separator of the items in the string")
    MsgBox (cell)

    Call split_std(cell, separator)
End Sub