0

I have this function in Excel Vba:

Function split_std(cell As String, separator As String)

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

End Function

And I am calling it this way:

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

But when finishing writing the call to the function, error: "Expected: =" appears. I already tried by removing brackets, but I can't get it to work. Help please!

2 Answers 2

1

Try this instead:

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
Sign up to request clarification or add additional context in comments.

Comments

0

Close:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.