2D阵列Ubound中的Excel VBA总列数

时间:2018-04-30 20:22:26

标签: arrays excel excel-vba multidimensional-array vba

我想要计算2D数组列中的所有数据

我的下面的代码被破坏了,代码循环遍历2D数组的内容,并且一旦Column等于" Net Amount Local"我想暂停并总结该列中的所有值(数组维度)

Sub Evaluate_PositionV()

Dim aMapRow As Integer, aMapCol As Integer
Dim Ttraded As Double

Ttraded = 0

For aMapRow = LBound(arrayTraded, 1) To UBound(arrayTraded, 1)
        For aMapCol = LBound(arrayTraded, 2) To UBound(arrayTraded, 2)
            Debug.Print arrayTraded(aMapRow, aMapCol)
                If arrayTraded(aMapRow, aMapCol) = "Net Amount Local" Then
                    for each i in UBound(arrayTraded, 1)

                            aMapRow = aMapRow + 1
                            Ttraded = Ttraded + arrayTraded(aMapRow, aMapCol)
                End If
    Next aMapCol
Next aMapRow

End Sub

1 个答案:

答案 0 :(得分:2)

它看起来应该是这样的(因为我没有你的数据所以我无法测试):

Sub Evaluate_PositionV()
    Dim aMapRow As Integer, aMapCol As Integer
    Dim Ttraded As Double

    Ttraded = 0
    For aMapRow = LBound(arrayTraded, 1) To UBound(arrayTraded, 1)
        For aMapCol = LBound(arrayTraded, 2) To UBound(arrayTraded, 2)
            Debug.Print arrayTraded(aMapRow, aMapCol)
            If arrayTraded(aMapRow, aMapCol) = "Net Amount Local" Then
                For i = 1 To UBound(arrayTraded, 1)
                    Ttraded = Ttraded + arrayTraded(i, aMapCol)
                Next i
            End If
        Next aMapCol
    Next aMapRow
End Sub