Thread: Set Range error
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Alan Beban Alan Beban is offline
external usenet poster
 
Posts: 200
Default Set Range error

Die_Another_Day wrote:
Because Cells, unless otherwise told, references cells on the
ActiveSheet. So you are tell it in effect:
Set fromRange = Worksheets("AAdata").Range(ActiveSheet.Cells(2, 4), _
ActiveSheet.Cells(2, 11))
What you really want to tell it is this:
Set fromRange =
Worksheets("AAdata").Range(Worksheets("AAdata").Ce lls(2, 4), _
Worksheets("AAdata").Cells(2, 11))
Which could be shortened to this:
With Sheets("AAdata")
Set fromRange = .Range(.Cells(2,4),.Cells(2,11))
End With


Or shortened further to

Set rng = Sheets("AAdata").Range("A1")
Set fromRange = Range(rng(2, 4), rng(2, 11))

Alan Beban