parenthesis or not
In general you use parenthesis when:
1) assigning result to a variable:
Correct:
Set rng = wks.Cells.Find("*", , , , xlByRows, xlPrevious)
Incorrect:
Range("A1:A5").Copy (Destination:=Range("C1"))
2) doing something with result:
wks.Cells.Find("*", , , , xlByRows, xlPrevious).Activate
3) using with Call
keyword:
Correct:
Call Range("A1:A5").Copy (Destination:=Range("C1"))
Incorrect:
Call Range("A1:A5").Copy Destination:=Range("C1")
You don't use parenthesis when:
1) calling any method without assigning result to a variable or doing something with result or using Call
keyword:
Correct:
Range("A1:A5").Copy Destination:=Range("C1")
Incorrect:
Call Range("A1:A5").Copy Destination:=Range("C1")
Range("A1:A5").Copy(Destination:=Range("C1"))
label:=value or value
This feature called named arguments and it's very convenient.
A function call using named arguments differs from a regular function call in that the values are passed by associating each one with a parameter name, instead of providing an ordered list of values.
Named arguments are especially useful when you are calling a procedure that has optional arguments. If you use named arguments, you don't have to include commas to denote missing positional arguments. Using named arguments makes it easier to keep track of which arguments you passed and which you omitted. See more here.
E.g. Find
method has 9 parameters (1 required and 8 optional) and if you want to specify 7th
parameter, you have two options:
Option1:
Set it using it's order:
Set rng = wks.Cells.Find("*", , , , , , True)
and when you see code like in line above, it's very hard to understand meaning of True
because you should count place of this argument and look in documentation for details.
Option2:
Set it using named arguments:
Set rng = wks.Cells.Find(What:="*", MatchCase:=True)
which makes your code much more readable.
Additionally, when using named parameters, you can change order of arguments:
Set rng = wks.Cells.Find(MatchCase:=True, What:="*")