0

New to VBA but years of experience with assembler, C and C#. I have created a Private Sub called CPScenarioData(wsname as String, rownum As Integer). When I call the procedure using the statement:

 CPScenarioData(wsname, l)

I get an error 'Compile error: Expected =', however when I preceded the statement with Call no error occurs, why is this. I have other Private subs that I call without using Call that work fine. I am sure there is a simple answer or mistake I have made and will feel very sheepish when I see the answer but that's life. I am using Excel 2013 VBA. Thank you for your help.

Community
  • 1
  • 1
D Barton
  • 9
  • 1
  • 1
    Lose the parentheses – Alex K. Aug 12 '16 at 14:37
  • Possible duplicate of [What are the rules governing usage of brackets in VBA function calls?](http://stackoverflow.com/questions/5413765/what-are-the-rules-governing-usage-of-brackets-in-vba-function-calls) – Alex K. Aug 12 '16 at 14:39

1 Answers1

1

It's a quirk (feature according to taste) of VB. To call a sub, you don't include brackets. So simply type:

CPScenarioData wsname, 1

Normally brackets are used to denote a Function, which returns a value. In VB you must provide a variable to receive the returned value. (Hence the compile error for missing =; it is expecting a = CPScenario(wsname, 1)).

Adding the word Call enables you to keep the brackets for Subs (equivalent of c# void).