简体   繁体   中英

Excel VBA Total Column in 2D array Ubound

I would like to total all the data in the column of a 2D array

My code below is broken, the code cycles through the contents of a 2D array and once the Column equals "Net Amount Local" I would like to pause and sum all the values within that Column (array dimension)

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

It should look like this (I can't test this since I don't have your data):

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM