Consulting

Results 1 to 4 of 4

Thread: How Beneficial Is "Destination:=" to Copy?

  1. #1

    How Beneficial Is "Destination:=" to Copy?

    When I do a copy I generally use the format:

    Range("A1").Copy Range("C2")
    But I just became aware of the "Destination:=" parameter, and I'm not sure what it does for you (if anything). If I used it then I would write:

    Range("A1").Copy Destination:=Range("C2")
    Seems like additional clutter if it's not doing anything (or is it??).

  2. #2
    BoardCoder
    Licensed Coder
    VBAX Expert mark007's Avatar
    Joined
    May 2004
    Location
    Leeds, UK
    Posts
    622
    Location
    Both lines of code above are equivalent.

    Naming the fields can be useful for some functions, for example suppose I had a procedure:

    sub MySub(Optional Arg1 as Integer, optional Arg2 as Integer, optional Arg3 as Integer)
    andf I wanted to pass an argument (2) to arg3 but nothing to arg1 or arg2. There are 2 ways or doing this:

    Mysub ,,2
    or

    MySub Arg3:=2
    Both do the same thing but the second is slightly neater in this case to avoid using commas - it is easier to read.

    If I only wanted to pass a value (5 say) to arg1 then I could use:

    MySub 5
    or
    MySub Arg1:=5
    As it's the first parameter I would be unlikely to use the second approach. The difference though is merely coding style and makes no real difference.

    "Computers are useless. They can only give you answers." - Pablo Picasso
    Mark Rowlinson FIA | The Code Net

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    If you think you can always rely on MS never to change arguments or their order, and never to accidentally issue a release without screwing some up, then there is no need to worry about using named arguments.

    But ...

    .
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Thanx, Guys. I get it. I just never thought of it in the context that mark007 explained. It's not so mysterious after all.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •