Excel VBA中的=和=之间有什么区别?

时间:2021-07-12 15:59:11

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

我一直在使用Excel一段时间,但我从来没有读过这两个运算符之间的区别(“无论我是否使用过两者”):=和Excel中的Excel

2 个解决方案

#1


8  

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

如您所知,=用于分配值或设置对象 - 例如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.

:=另一方面(像Comintern提到的那样),用来为某个命名参数赋值,afaik只在一个方法或函数中。

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.

考虑以下示例:您可以使用MsgBox“Hello World”,“Title1”之类的东西 - 以默认顺序指定MsgBox的参数 - 提示,默认的Buttons样式,然后是Title。

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

或者,可以使用:=写入MsgBox标题:=“Title1”,提示:=“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 , ,.

    没有必要为default-arguments指定空占位符,。

#2


2  

Let us take for example the Range.Find method

让我们以Range.Find方法为例

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

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"):

这是很多条件!但是你只想在Range中搜索数字2(“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)

#1


8  

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

如您所知,=用于分配值或设置对象 - 例如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.

:=另一方面(像Comintern提到的那样),用来为某个命名参数赋值,afaik只在一个方法或函数中。

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.

考虑以下示例:您可以使用MsgBox“Hello World”,“Title1”之类的东西 - 以默认顺序指定MsgBox的参数 - 提示,默认的Buttons样式,然后是Title。

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

或者,可以使用:=写入MsgBox标题:=“Title1”,提示:=“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 , ,.

    没有必要为default-arguments指定空占位符,。

#2


2  

Let us take for example the Range.Find method

让我们以Range.Find方法为例

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

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"):

这是很多条件!但是你只想在Range中搜索数字2(“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)