Reputation: 151
I've just started with VBA programming in Excel. One thing drew my attention when I saw some sentences were written with :=
and others with just an =
.
Examples:
Sub Change_Page_Name()
Worksheets(1).Name = "Prueba"
End Sub
Sub Add_Page()
Worksheets.Add After:=Worksheets("Hoja2")
End Sub
I made these two examples, but I'm confused because I don't know when I should use =
or :=
Upvotes: 1
Views: 59
Reputation: 53126
:=
is used with Named Parameter assignment. In your example After
is a parameter name for the .Add
Method of the Worksheets
object.
=
is used for both assignment and comparison. In Worksheets(1).Name = "Prueba"
you are assigning a value to the Worksheets(1)
object Name
parameter.
=
would also be used to test a Parameter value, eg If Worksheets(1).Name = "Prueba" Then
Upvotes: 3