2017-08-10 79 views
0

我在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 

但寫作整理的時調用該函數,出現錯誤:「Expected:=」。我已經嘗試刪除括號,但我無法得到它的工作。請幫助!

回答

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 
0

關閉:

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 Range, separator As String 

    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 CStr(cell.Value), separator 

End Sub