21

I'm trying to figure out why VBA is returning an error (Compile error: Expected: =) when I call a Subroutine and supply it with multiple parameters.

Sub customerController(cleanStructure As Boolean, firstCol As Integer, latCol As Integer, _
                    lngCol As Integer, Optional startRow As Long, Optional endRow As Long)
                    
Dim i As Long, j As Long, n As Long

If (cleanStructure = False) Then
    'customer data type
    If (startRow = "") Then i = 1
    If (endRow = "") Then j = countRows
    For n = i To j - i + 1
        generateURL(n, firstCol)
        newReadXMLData (url)
        ActiveSheet.Cells(i, latCol).Value = lat
        ActiveSheet.Cells(i, lngCol).Value = lng
    Next
End If

End Sub

The Subroutine that I'm calling requires two parameters:

Sub generateURL(row As Long, column As Long)
1
  • also dim firstCol as Long, or you will get another error Commented Nov 29, 2012 at 19:28

1 Answer 1

45

When calling more than 1 parameter (i.e. just generateURL(n) works) you need to either use

  • Call generateURL(n, firstCol) , or
  • generateURL n, firstCol

using Call is the better programming technique as it is clearer

As per MSDN:

You normally use the Call statement to call a procedure that does not return a value. If the procedure returns a value, the Call statement discards it. You are not required to use the Call statement when calling a procedure. However, it improves the readability of your code.

Sign up to request clarification or add additional context in comments.

3 Comments

I think the most reliable explanation and answer to this question is what we can find in the official documentation that Microsoft provides at msdn.microsoft.com/en-us/library/office/gg251432.aspx (Calling Sub and Function Procedures).
Well, you are not required to use the Call statement ...unless you are using parentheses, apparently.
It is wrong that with just one parameter there is no difference between using and not using the parentheses; the effect is different. It is subjective that using Call improves readability; in my opinion it doesn't.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.