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

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.

Leave a Comment