VBA如何在EXCEL中进行条件统计?

我希望VBA能够关联A列的商品名称,在E:G列的明细,将状态为正常和作废的金额,分别汇总统计到B列和C列中。

Sub 条件统计()

Dim refg As String
refg = ActiveSheet.UsedRange.Item(ActiveSheet.UsedRange.Count).Row

Range("B3:C4") = 0

For R = 3 To 4
For C = 2 To 3
For i = 3 To refg

If Cells(R, 1) = Cells(i, 5) And Cells(2, C) = Cells(i, 6) Then
Cells(R, C) = Cells(R, C) + Cells(i, 7)
End If
Next
Next
Next

End Sub

有附件


温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-03-06
用数据透视表不是更好
第2个回答  2015-03-06
B3=sumproduct((e:e=$a3)*(f:f=b$2),g:g)