View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Alan Beban[_4_] Alan Beban[_4_] is offline
external usenet poster
 
Posts: 171
Default Loading Excel Arrange into VBA array

If the functions in the freely downloadable file at
http://home.pacbell.net/beban are available to your workbook, the
following will do what you suggest. Starting with a range of 10 rows
and 15 columns, it loads the range values into arr (4th line), replaces
the 6th "column" of arr with the 7th (5th line), reloads arr with the
resulting 1st 6 "columns", (6th line), then increases the number of
"columns" of arr to 20 (7th line).

Sub testIt()
Dim rng As Range, arr As Variant, numRows As Long
Set rng = Sheets(2).Range("A1:O10")
numRows = rng.Rows.Count
arr = rng.Value
ReplaceSubArray arr, SubArray(arr, 7, 7, 1, numRows), 1, 6
arr = SubArray(arr, 1, 6, 1, numRows)
ReDim Preserve arr(numRows, 20)
End Sub

Alan Beban

wrote:
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