View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Alex J Alex J is offline
external usenet poster
 
Posts: 85
Default Loading Excel Arrange into VBA array

Terry,

For the second part of your question,

Redim Preserve UploadArray(Lbound(UploadArray,1) to Ubound(UploadArray,1),
Lbound(UploadArray,2) to Ubound(UploadArray,2) + 100)

Will let you add 100 columns (for example) and maintain the data you have
already put into the array. Note that Redim Preserve only lets you increase
the last dimension of the array.

For the first question....

It's more like personal philosophy, but my technique is to read everything
as fast as possible (sheet reads take time, sheet writes take LOTS of time).

After that, it is always possible to transfer array components to another
array, or a collection, etc. It also, for you, really depends on what you
might be writing back to the sheet, and how that needs to be arranged.

Alex J


wrote in message
om...
I have a procedure that loads a 2D dynamic excel range inot a VBA
array.

Range("xlEntireXlArray").Activate
With Range("xlEntireXlArray")
ExcelRowCount = .Rows.Count
ExcelColumnCount = .Columns.Count
UploadArray = .Resize(ExcelRowCount, ExcelColumnCount)
End With

The VBA array will always represent the dynamic excel range.

What if I want more control over the columns with the excel range that
actually get loaded into the array. Assume the excel range is 10 rows
by 15 columns. But I do not want all 15 columns in the VBA array. If
I only wanted columns 1-5, and 7 (6 columns) loaded into the array, is
it possible to load these columns individually? How would you write
the 6 different load statements? I am not looking for a form here
that gives me the option of picking columns. I will want to do this
manually with code.

Secondly when I now pull these 6 columns into my VBA array, I want the
second dimension of my VBA array to be larger than the number of
columns I pulled in. Say I want it to be 20 elements across instead
of just 6. Do I just simply dimension it for 20? I want it to be
large because I want to do some additional calcs and store the values
in the VBA array.

TS