View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
colin_e colin_e is offline
external usenet poster
 
Posts: 5
Default Range.Copy only works with a named destination parameter?

Hmm, I hadn't realised was a () dereference operator, even in a subroutine or
function call. I'm relatively new to VBA, I've not seen this in other
languages.

It's confusing because the interactive editor offers up brackets around the
parameter when you are typing the function , kind-of encourages using the
brackets.

Anyway, thanks for the info, at least I now know what's going on.

Regards: Colin

"Tom Ogilvy" wrote:

(target)

dereferences target and returns the value of target. Remove the parentheses
in accordance with VBA syntax. When calling and referencing, use parentheses
only when dictated by the syntax.

--
Regards,
Tom Ogilvy


"colin_e" wrote:

Having an odd problem with the Range.Copy method.

This code:

Set source= Range("VL_Source")
Set target = VL.Offset(1).Resize(1, 1)
source.Copy Destination:=target

works fine. However the same thing with positional parameter:

Set source= Range("VL_Source")
Set target = VL.Offset(1).Resize(1, 1)
source.Copy (target)

fails with the error-

Run-time error '1004':
Copy methid of Raneg class failed

As far as I can see they mean exactly the same thing (source and target are
both declared as type Range). Any idea why this happens?

Regards; Colin