ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   what does the operator ":=" mean? (https://www.excelbanter.com/excel-programming/416325-what-does-operator-%3D-mean.html)

Michael/what does the operator := mean

what does the operator ":=" mean?
 
in Office VB code:
what does the operator ":=" mean?

example:
Worksheets("Daily Targets").Range("A5:N5").Copy _
Destination:=Worksheets("Daily Targets").Range("A" & CStr(rowCounter))

i wrote this code but i copied the it from the HELP, & then i changed the
names & variables. BUT, i'd like to understand what does the operator := is
filling for, is it an object assigning or what ... i'm not sure ??!!!

regards,
Michael

JLGWhiz

what does the operator ":=" mean?
 
Probably the easiest way to explain it is that the colon (:) tells VBA that
it is not assigninng a variable. In other words if you entered this
statement:

Destination = Range("A1")

, then VBA would treat Destination as a variable and unless you put Set in
front of Destination it would give you an error message.

But with the colon and equal sign (:=) VBA knows that Destination is a
parameter of the Copy and Paste method and not a variable assignment.


"Michael/what does the operator ":=" mean" wrote:

in Office VB code:
what does the operator ":=" mean?

example:
Worksheets("Daily Targets").Range("A5:N5").Copy _
Destination:=Worksheets("Daily Targets").Range("A" & CStr(rowCounter))

i wrote this code but i copied the it from the HELP, & then i changed the
names & variables. BUT, i'd like to understand what does the operator := is
filling for, is it an object assigning or what ... i'm not sure ??!!!

regards,
Michael


Andy Pope

what does the operator ":=" mean?
 
Hi,

It's the syntax for named arguments.

From help file:
A named argument consists of an argument name followed by a colon and an
equal sign (:=), followed by the argument value.

For more details search help using "Understanding Named and Optional
Arguments"

Cheers
Andy

Michael/what does the operator := mean wrote:
in Office VB code:
what does the operator ":=" mean?

example:
Worksheets("Daily Targets").Range("A5:N5").Copy _
Destination:=Worksheets("Daily Targets").Range("A" & CStr(rowCounter))

i wrote this code but i copied the it from the HELP, & then i changed the
names & variables. BUT, i'd like to understand what does the operator := is
filling for, is it an object assigning or what ... i'm not sure ??!!!

regards,
Michael


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info

JLatham

what does the operator ":=" mean?
 
Just to confuse matters further. Using named arguments allows you to just
enter the non-default arguments for a command and enter them in any order
rather than having to enter something for every possible argument and to have
to do it in a particular order. The := tells the VBA engine that what
follows is a value to be used as the specific argument indicated by the entry
on the left side of the := indicator.

"Michael/what does the operator ":=" mean" wrote:

in Office VB code:
what does the operator ":=" mean?

example:
Worksheets("Daily Targets").Range("A5:N5").Copy _
Destination:=Worksheets("Daily Targets").Range("A" & CStr(rowCounter))

i wrote this code but i copied the it from the HELP, & then i changed the
names & variables. BUT, i'd like to understand what does the operator := is
filling for, is it an object assigning or what ... i'm not sure ??!!!

regards,
Michael



All times are GMT +1. The time now is 10:31 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com