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

时间:2017-10-16 20:42:36

标签: 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
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

1 个答案:

答案 0 :(得分:0)

我认为如果删除不必要的

,一切都会正常工作
  

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