How to return the number of dimensions of a (Variant) variable passed to it in VBA

dimensions, excel, variant, vba

Solution

Function getDimension(var As Variant) As Long
    On Error GoTo Err
    Dim i As Long
    Dim tmp As Long
    i = 0
    Do While True
        i = i + 1
        tmp = UBound(var, i)
    Loop
Err:
    getDimension = i - 1
End Function

That's the only way I could come up with. Not pretty….

Looking at MSDN, they basically did the same.

Problem

Does anyone know how to return the number of dimensions of a (Variant) variable passed to it in VBA?

Original source

Related problems