What is the difference between := and = in Excel VBA

Moreno picture Moreno · Nov 23, 2016 · Viewed 16.4k times · Source

I have been working with Excel for a while, yet i have never read what is the difference between these two operators ("regardless of i have used both") := and = in Excel VBA

Answer

Martin Dreher picture Martin Dreher · Nov 23, 2016

As you already know, = is used to assign values or set objects - e.g. i=1

:= on the other hand (like Comintern mentioned), is used to to assign a value to a certain named argument, afaik only ever inside a method or function.

Consider the following example: you could use something like MsgBox "Hello World", , "Title1" - specifying MsgBox's arguments in the default order - the prompt, the default Buttons-style, then the Title.

Alternatively, one could use := to write MsgBox Title:="Title1", prompt:="Hello world"

Notice that

  • the order of the arguments is of no importance here and

  • there is no need to specify empty placeholders for default-arguments , ,.