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
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.
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.
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.
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.
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 , ,
.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With