Hi
Some more comments about the assignment operator ":="
":=" is an assignement operator for parameters. You can use it with object methods but also with for ex. functions. It's optional if you respect the order of the parameters
It's used usually in 2 cases
1 - for documentation or readability of the code
ex.: These 2 statements are equivalent:
Code:
Msgbox "Hi!",vbYesNo,"Greeting"
MsgBox Prompt:="Hi!", Buttons:=vbYesNo, Title:="Greeting"
You can argue, however, that the second is more informative or makes the code easier to read and understand since you are seeing the names of the parameters.
2 - To use just some parameters and avoid listing empty parameters
Ex.:
The Application.Inputbox method is defined in the help as:
Code:
expression.InputBox(Prompt, Title, Default, Left, Top, HelpFile, HelpContextID, Type)
If you want to select a range you can use:
Code:
Dim r As Range
Set r = Application.InputBox(Prompt:="Select range", Type:=8)
Just listing the first and last parameters.
You could also use
Code:
Dim r As Range
Set r = Application.InputBox("Select range", , , , , , , 8)
but it's not so easy to read.
Remark:
1 - If you use the := operator you can write the parameters in whatever order you like, ex.:
Code:
MsgBox Title:="Greeting", Buttons:=vbYesNo, Prompt:="Hi!"
2 - You can also use the := with just the parameters that do not follow the default order, like
Code:
Dim r As Range
Set r = Application.InputBox("Select range", Type:=8)