Arrays 从创建矩阵的循环之外的矩阵中获取值

Arrays 从创建矩阵的循环之外的矩阵中获取值,arrays,vba,loops,for-loop,matrix,Arrays,Vba,Loops,For Loop,Matrix,我试图编写一个if语句,但我需要从“矩阵”矩阵/数组中获取一个值。我无法使VBA使h等于“矩阵”中插槽1,1中的值。我已经打印了矩阵,以确保它正确地保存了值,并且是正确的。如何在创建循环之外的矩阵中获取值 Option Explicit Option Base 1 Private Sub CommandButton1_Click() Dim numberofcases As Single, r As Integer, i As Single, j As Integer, c As Single

我试图编写一个if语句,但我需要从“矩阵”矩阵/数组中获取一个值。我无法使VBA使h等于“矩阵”中插槽1,1中的值。我已经打印了矩阵,以确保它正确地保存了值,并且是正确的。如何在创建循环之外的矩阵中获取值

Option Explicit
Option Base 1
Private Sub CommandButton1_Click()
Dim numberofcases As Single, r As Integer, i As Single, j As Integer, c As 
Single
Dim matrix() As String, max As Single
Dim loadmatrix() As String, loadtypes As Single, numbertypes As Single
Dim STAADloadmatrix() As String, countrow As Single, countcolumn As Single
Dim h as single

max = ((Cells(Rows.count, "B").End(xlUp).Row))
loadtypes = ((Cells(Rows.count, "L").End(xlUp).Row))


j = 1
c = 5
i = 1
ReDim matrix(i, j)
For r = 2 To max
    ReDim matrix(i, j)
    j = 1
    If Cells(r, c) = "" Then
    ElseIf Cells(r, c) > 0 Then
    matrix(i, j) = Cells(r, c)
    j = 2
    ReDim matrix(i, j)
    matrix(i, j) = Cells(r, (c - 2))
    i = i + 1
    End If
Next r

h = matrix(1,1)

End sub

我想如果你删除不必要的内容,一切都会很好

Redim矩阵(i,j)

在循环内部:

    For r = 2 To max
    j = 1 If Cells(r, c) = "" Then
    ElseIf Cells(r, c) > 0 Then
    matrix(i, j) = Cells(r, c)
    j = 2
    matrix(i, j) = Cells(r, (c - 2))
    i = i + 1
    End If
    Next r

我想如果你删除不必要的内容,一切都会很好

Redim矩阵(i,j)

在循环内部:

    For r = 2 To max
    j = 1 If Cells(r, c) = "" Then
    ElseIf Cells(r, c) > 0 Then
    matrix(i, j) = Cells(r, c)
    j = 2
    matrix(i, j) = Cells(r, (c - 2))
    i = i + 1
    End If
    Next r
ReDim
如果不使用“保留”,则会删除所有数组内容<代码>重拨不带“保留”将擦除所有数组内容。