VBA check if array is one dimensional

后端 未结 5 1692
我寻月下人不归
我寻月下人不归 2020-12-08 12:01

I have an array (that comes from SQL) and can potentially have one or more rows.

I want to be able to figure out if the array has just one row.

UBound doesn\

5条回答
  •  死守一世寂寞
    2020-12-08 12:38

    For a 2D array (or more dimensions), use this function:

    Function is2d(a As Variant) As Boolean
        Dim l As Long
        On Error Resume Next
        l = LBound(a, 2)
        is2d = Err = 0
    End Function
    

    which gives :

    Sub test()
        Dim d1(2) As Integer, d2(2, 2) As Integer,d3(2, 2, 2) As Integer
        Dim b1, b2, b3 As Boolean
    
        b1 = is2d(d1) ' False
        b2 = is2d(d2) ' True
        b3 = is2d(d3) ' True
    
        Stop
    End Sub
    

提交回复
热议问题