View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.programming
Alan Beban[_2_] Alan Beban[_2_] is offline
external usenet poster
 
Posts: 783
Default VBA Matrix class

R Avery wrote:

. . . Also, are there any builtin functions that can return a subset of
columns from the original array? For example, if I want to get a
variant array containing only columns 2, 3 and 5.

Well, though somewhat kludgy you could always dump the array to the
worksheet, extract the three columns on the worksheet, and retransfer
them to an array. No guarantees that it's faster than a UDF.

E.g., with Sheets(9) active and without declarations(watch the word wrap)

Sub sldkgghlkh()
Set rng = Sheets(7).Range("b1:f24") 'The first two lines are
arr = rng 'arbitrary to load array
Set tempRange = Range("A1").Resize(UBound(arr), UBound(arr, 2))
tempRange.Value = arr
Set tempRange2 = Range("H1").Resize(UBound(arr), 3)
tempRange2.FormulaArray = "=INDEX(" & tempRange.Address & ",ROW(1:"
& UBound(arr) &"),{2,3,5})"
arr = tempRange2
tempRange.ClearContents 'To tidy up
tempRange2.ClearContents 'To tidy up
Sheets(8).Range("a1:c" & UBound(arr)).Value = arr 'This
is just to 'check to confirm
'transfer to array
End Sub

Alan Beban