Reading large data into Excel using arrays or otherwise
Can someone please give me some pointers with regard to working with large data (say 1 million rows, 200 columns) in Excel 2010?
Having the data on the worksheet from cell A1 onwards, I am trying to read it in memory via an array.
QUESTION 1. What is the difference between these two methods?
Method 1:
dim myarray()
myarray = cells(1,1).currentregion.value
Method 2:
dim myarray
myarray = cells(1,1).currentregion
The second method seems to be able to read "more data" than the first, though both fail if the data is "too big", with an out of memory message.
I have also tried this:
Method 3:
dim rng as range
set rng = thisworkbook.cells(1,1).currentregion
This method seems to be able to read the large data EVERY time and I can retrieve any element like an array, ie:
dim a as integer
a = rng.cells(10000,50) would return a value
QUESTION 2. Why use arrays if Method 3 ALWAYS enables one to read large data?
It depends what you want to
It depends what you want to do with the data.
Looping an array is faster than a range.