Excel VBA - How to Redim a 2D array?

前端 未结 9 2186
闹比i
闹比i 2020-11-30 06:57

In Excel via Visual Basic, I am iterating through a CSV file of invoices that is loaded into Excel. The invoices are in a determinable pattern by client.

I am readin

9条回答
  •  长情又很酷
    2020-11-30 07:32

    You could do this array(0)= array(0,1,2,3).

    Sub add_new(data_array() As Variant, new_data() As Variant)
        Dim ar2() As Variant, fl As Integer
        If Not (isEmpty(data_array)) = True Then
            fl = 0
        Else
            fl = UBound(data_array) + 1
        End If
        ReDim Preserve data_array(fl)
        data_array(fl) = new_data
    End Sub
    
    Sub demo()
        Dim dt() As Variant, nw(0, 1) As Variant
        nw(0, 0) = "Hi"
        nw(0, 1) = "Bye"
        Call add_new(dt, nw)
        nw(0, 0) = "Good"
        nw(0, 1) = "Bad"
        Call add_new(dt, nw)
    End Sub
    

提交回复
热议问题