VBA array cells formula: error 1004 application-defined or object-defined error

JPF

New Member
Joined
Aug 6, 2010
Messages
2
Hi all-

Why does the following code cause the run-time error unless I first select sheet(1)?

Code:
my_array = Sheets(1).Range(Cells(1, 1), Cells(3, 1)).Resize(3,  1)
And, related, why does the following code work (no error) regardless of which sheet is selected?

Code:
my_array =  Sheets(1).Range("a1:a3").Resize(3, 1)
I do not understand why hard coding the range with "a1:a3" should be different than using the "cells" method.

In both cases, I am using
Code:
Dim my_array As Variant 
ReDim  my_array(1 To 3, 1)
I am using Excel 2003 SP3 with Windows XP.

-Jason
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
You need to fully qualify the sheet reference:

Code:
my_array = Sheets(1).Range(Sheets(1).Cells(1, 1), Sheets(1).Cells(3, 1)).Resize(3, 1)
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top