我想要计算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
答案 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