• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Intro

KishorKK

Member
HI All,


Pls tell me why to put ":" before writing anything like

'Range("a1:a10").Copy Destination:=Range("b1")

and when using color why to give vbRed like this.Pls explain

Thanks,
Kishor


POST MOVED BY MOD

.
 
Last edited by a moderator:
":=" denotes parameter for method (ex. ".Copy").

You can omit it as long as syntax order is honored. View the syntax usage within VBE & also have a look at Range.Copy method.
https://msdn.microsoft.com/en-us/library/office/ff837760.aspx

And link below for difference between parameters and arguments.
https://msdn.microsoft.com/en-us/library/9kewt1b3.aspx

Taking Scripting.Dictionary as an example all 4 are valid code.
Syntax: dictionary.add key, item
Code:
Dim dict as Object
Set dict = CreateObject("Scripting.Dictionary")

dict.add Item:="Contact", Key:="Name"
dict.add "Name", "Contact"
dict.add Key:="Name", Item:="Contact"
dict.Item("Name") = "Contact"

Edit: Technically, 4th one isn't using ".Add" method. So 3 ways to write ".Add" method parameters. Note that order does not matter, if you specify parameter with ":=".

There are multiple ways of assigning colour. But vbRed etc, gives quick reference for base colour pallets available, without memorizing/looking up color index or some other color scheme.
 
Last edited:
Back
Top