I have a some very large data sets in Excel that I need to parse through - and doing it in an array is faster than looping through the data in the worksheet. Loading all of the data into an array is causing memory problems (the data sets ARE that large), so I plan on loading subsets of the data into an array, processing that, then loading another subset. I was hoping to use the array "feature" of defining the LBound and UBound to help me keep track of where I am in the worksheet. But I find that assigning the worksheet values to the array changes the bounds. The following code demonstrates the problem ...
Sub myTest3()
Dim myRange As Range
Dim myArray As Variant
Dim myOffset As Long
myOffset = 10
Set myRange = Worksheets("RawData").Range("A1").CurrentRegion
ReDim myArray(myOffset To myRange.Rows.Count, myRange.Columns.Count)
MsgBox LBound(myArray, 1) & " to " & UBound(myArray)
Set myRange = myRange.Offset(myOffset, 0).Resize(myRange.Rows.Count - myOffset, myRange.Columns.Count)
myArray = myRange.Value2
MsgBox LBound(myArray, 1) & " to " & UBound(myArray)
End Sub
The first MsgBox gives me "10 to 10931". The second MsgBox gives me "1 to 10921".
Any ideas on maintaining the bounds on the array as I originally defined them? I know looping through the worksheet to make the assignment would do it, but it would be slow.
Thanks in advance.
ReDimstatement to redeclare the array with a lower bound of10, here:ReDim myArray(myOffset to .... What exactly are you trying to do with themyOffsetvariable? I think that's the cause. - David Zemensthismay help you. - user2140173