View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
jayklmno jayklmno is offline
external usenet poster
 
Posts: 58
Default Setting a range?

Try running it when it isn't the active sheet. My EndRow and EndCol values
are valid, but it is getting an Runtime 1004 - Application-defined or object
defined error.

This macro is accessing data on another tab in the spreedsheet, not the
active tab.

"Trevor Shuttleworth" wrote:

Works for me.

What values do you get for EndRow and EndCol ?

What error message do you get ?

Regards

Trevor


"jayklmno" wrote in message
...
What is wrong with this code?

Dim MyArray As Variant
Dim MyRange As Range
Dim EndRow As Long
Dim EndCol As Integer

Debug.Print Sheets("Data").Range("A1")
EndRow = Sheets("Data").Range("A1").End(xlDown).Row
EndCol = Sheets("Data").Range("A1").End(xlToRight).Column

Set MyRange = Worksheets("Data").Range(Cells(1, 1), Cells(EndRow, EndCol))
MyArray = MyRange

The Set MyRange line errors out with an Runtime Error. EndRow and EndCol
are
valid locations, so it has to be how I use the cells in the range
statement?
Any help?