Count Array Dimensions
Function DimensionCount(aInput As Variant) As Long
‘Returns the number of dimensions of an array
‘aInput is an array
Dim lDim As Long
Dim lTemp As Long
If IsArray(aInput) Then
On Error Resume Next
Do
lDim = lDim + 1
lTemp = LBound(aInput, lDim)
Loop Until Err.Number <> 0
On Error GoTo 0
lDim = lDim - 1
Else
lDim = 0
End If
DimensionCount = lDim
End Function
Rob van Gelder:
Here’s the code I use for that purpose.
Sub test()
Dim arr(1, 2, 3, 4) As Long
Dim i As Long
On Error Resume Next
Do: i = i - (LBound(arr, i + 1) * 0 = 0): Loop Until Err.Number
On Error GoTo 0
MsgBox i
1 July 2004, 3:20 pmEnd Sub
Colo:
Very nice approach Rob!
2 July 2004, 4:16 ammarco vismara:
dl = UBound(WorksheetFunction.Transpose(divmatrix))
9 November 2006, 9:30 am