Loading numbers from cells into an array

ZainE

New Member
Joined
Feb 11, 2011
Messages
13
Hi. I am trying to copy some data from cells into an array but there's a large amount of data and it takes quite long...

This is what I'm doing:

Code:
Sub Test()
Dim myArr(20000, 500) As Double
Dim r, c As Integer
For r = 1 To 20000
    For c = 1 To 500
        myArr(r, c) = Sheets("Sheet2").Cells(r, c).Value
 
        'I also tried the following:
        'myArr(r, c) = Sheets("Sheet2").Range("A1").Offset(r, c).Value
    Next c
Next r
 
End Sub

Is there perhaps a quicker easier way to copy the data into the array?
Thanks
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Define myArr as variant then

myArr=Sheets("Sheet2").range("A1:C2000").Value

or whatever
 
Upvote 0
Define myArr as variant then

myArr=Sheets("Sheet2").range("A1:C2000").Value

or whatever

I tried the following but it still doesn't work...

Code:
Sub Test()
Dim myArr(20000, 500) As Variant
myArr = Sheets("Sheet2").Range("A1:SF20000")

End Sub

I get a Compile error: Can't assign to array.
 
Upvote 0
Change this
Dim myArr(20000, 500) As Variant
to
Dim myArr As Variant

Hi again

Thanks for your help so far - but I get an error (subscript out of range) when I try to reference the array. So if I say myArr(1) I get an error.

How do I use the array?
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,909
Members
452,949
Latest member
beartooth91

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