View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
R Avery R Avery is offline
external usenet poster
 
Posts: 220
Default VBA Matrix class

I have conducted my own speed tests using
Application.Worksheetfunction.Index, and it is slower than a custom
function by a factor of 1.4 to 30, depending on the size of the array.

Does the Index function offer any benefits over what my ArraySlice
function (other than the fact that I would need to add code to make it
handle Rows as well)?

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.




Sub sldkgghlkh()
Dim x As Variant, vnt As Variant
Dim i As Long
Dim myTimer As New clsTimer

x = Selection

Debug.Print "Application.Index"
myTimer.StartTimer
For i = 1 To 10000
vnt = Application.WorksheetFunction.Index(x, 3)
Next i
myTimer.StopTimer
Debug.Print myTimer.PerformanceString


Debug.Print "Custom Function"
myTimer.StartTimer
For i = 1 To 10000
vnt = ArraySlice(x, 3)
Next i
myTimer.StopTimer
Debug.Print myTimer.PerformanceString
End Sub



Private Function ArraySlice(varArray As Variant, ColNum As Long) As Variant
Dim vntCol As Variant
Dim i As Long

ReDim vntCol(LBound(varArray, 1) To UBound(varArray, 1))
For i = LBound(varArray, 1) To UBound(varArray, 1)
vntCol(i) = varArray(i, ColNum)
Next i
ArraySlice = vntCol
End Function