Abstract

How do you determine the number of dimensions of an array?

Appendix – ArrayDim Code

Please read my Disclaimer.

Function ArrayDim(v As Variant) As Long
'Returns number of dimensions of an array or 0 for
'an undimensioned array or -1 if no array at all.
'Source (EN): http://www.sulprobil.com/arraydim_en/
'Source (DE): http://www.bplumhoff.de/arraydim_de/
'(C) (P) by Bernd Plumhoff 10-May-2010 PB V0.1
Dim i As Long
ArrayDim = -1
If Not IsArray(v) Then Exit Function
On Error Resume Next
'Err.Clear 'Not necessary
Do While IsNumeric(UBound(v, i + 1))
    If Err.Number <> 0 Then Exit Do
    i = i + 1
Loop
ArrayDim = i
End Function

Please read my Disclaimer.

ArrayDim.xlsm [15 KB Excel file, open and use at your own risk]