The difference between
Range("A1").Copy (Range("E5"))
and
Range("A1").Copy Range("E5")
is that the first one converts the ByRef
argument into ByVal
while the second does not. The parenthesis here stands for a conversion and not for what you expected.
Note that you must only use the parenthesis when you use a function (that returns a value) but not when using a procedure.
Example
a = MyFunction(Parameter1, Parameter2) 'correct with parenthesis
MyProcedure Parameter1, Parameter2 'correct w/o parenthesis
a = MyFunction Parameter1, Parameter2 'it will error
MyProcedure(Parameter1, Parameter2) 'it will error
now with only one parameter
a = MyFunction(Parameter1) 'correct with parenthesis
MyProcedure Parameter1 'correct w/o parenthesis
a = MyFunction Parameter1 'it will error
MyProcedure (Parameter1) 'it will NOT error but convert ByRef into ByVal !!!
The last line of the above example does something completly different than you expected. You can notice the extra space between the procedure name and the parenthesis. And it is the same like the following syntax
a = MyFunction((Parameter1), (Parameter2)) 'convert ByRef into ByVal
MyProcedure (Parameter1), (Parameter2) 'convert ByRef into ByVal
So we can note down:
- If a function returns a value that we want to write into a variable:
You must use parenthesis: a = MyFunction(Parameter1)
- If a procedure (or function) does not return a value then:
You must not use parenthesis: MyProcedure Parameter1