Thread: Set Range error
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Set Range error

If your code is in a general module, it should work.

But I'm guessing that your code is behind a worksheet. And it's not behind
AAdata.

Unqualifed ranges in a general module will refer to the activesheet.
Unqualified ranges behind a worksheet will belong to the worksheet that owns the
code.

I'd use:

with worksheets("aadata")
set fromrange=.range(.cells(2,4),.cells(2,11))
'or just
'set fromrange = .range("D2:K2")
end with



Randy Spleen wrote:

I'd appreciate some insight about setting ranges with Excel 2003 VBA.
In particular, why does THIS work

Dim fromRange as Range
...
Worksheets("AAdata").Activate
Set fromRange = Range(Cells(2, 4), Cells(2, 11))

And THIS give a Run-time "Application-defined or object-defined error",
#1004, error:

Dim fromRange as Range
...
Set fromRange = Worksheets("AAdata").Range(Cells(2, 4), Cells(2, 11))

TIA
R. Spleen


--

Dave Peterson