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

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

+5
source share
2 answers

As you already know, = used to assign values ​​or set objects - for example. i=1

:= on the other hand (for example, the mentioned Comintern) is used to assign a value to a specific argument with the name afaik only ever inside a method or function.

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

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

note that

  • the order of the arguments is irrelevant here and

  • no need to specify empty placeholders for the default arguments,,.

+7
source

Take, for example, the Range.Find method

Find (what, after, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte, SearchFormat)

These are LOT conditions for installation! But you just need a simple number 2 search in Range("A1:A500") :

Without an operator := you will need to use commas to set any optional variables:

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

Using the operator := you can specify what conditions you want, without specifying all the default settings:

 Range("A1:A500").Find(what:=2, lookin:=xlValues) 
+1
source

Source: https://habr.com/ru/post/1260219/


All Articles