Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 767
Moreno Avatar asked Nov 23 '16 15:11

Moreno


People also ask

What is the difference between value and Value2 in VBA?

The only difference between this property and the Value property is that the Value2 property doesn't use the Currency and Date data types. You can return values formatted with these data types as floating-point numbers by using the Double data type.

How do you write equal in VBA?

It is a logical function, so the output returned by this function is either “True” or “False.” We know that the equal operator is “=” this but not equal is “<>” in VBA, so whatever the value we get from the equal operator, we will get the exact opposite value using the Not Equal operator.

Is Excel VBA different from Excel?

VBA is a programming language that was developed by Microsoft Corp., and it is integrated into the major Microsoft Office applications, such as Word, Excel, and Access. The VBA programming language allows users to access functions beyond what is available in the MS Office applications.

What is difference between Excel VBA and macros?

VBA is a programming language for developing automated tasks for Excel and other Microsoft Office programs like Word and PowerPoint while macros is a collection of commands that is used to replace a repetitive series of keyboard and mouse actions in an application such as MS Excel.


2 Answers

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 , ,.

like image 156
Martin Dreher Avatar answered Sep 28 '22 21:09

Martin Dreher


Let us take for example the Range.Find method

expression.Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte, SearchFormat)

That is a LOT of conditions to set! But you just want a simple search of the number 2 in Range("A1:A500"):

Without the := operator, you would have to use commas to get to any optional variables to set:

Range("A1:A500").Find(2, , xlValue, , , , , , )

With the := operator, you can specify which conditions you want without delineating through all the default settings:

Range("A1:A500").Find(what:=2, lookin:=xlValues)
like image 24
Chrismas007 Avatar answered Sep 28 '22 22:09

Chrismas007