使用VBA汇总具有特定值的所有事件

时间:2014-07-28 05:34:16

标签: excel-vba vba excel

我有一张这样的表格,例如:

A             B
=========================
AB1234        51
AB5678        61
AB1234        71
AB9876        10

VBA将在Col A中查找AB1234,然后从col B返回值,但我的表中有两个(或更多)。我想总结一下col B的所有事件。

这是我的代码

With Workbooks("ABC.xls").Worksheets("LOCATION").Range("A1:A1500")
Set Rng3 = .Find(What:=this_Value, LookIn:=xlValues, MatchCase:=False)

If Not Rng3 Is Nothing Then
    For Each StockCell In Rng3
        Workbooks(this_File).Worksheets("Data").Activate
        StockValue = StockValue + Workbooks("ABC.xls").Worksheets("LOCATION").Range("B" & Range(StockCell.Address).Row).Value
    Next StockCell
End If
Workbooks(this_File).Worksheets("Data").Range("A" & this_WorkingRow) = StockValue
StockValue = 0
End With

上面的代码只返回第一个值,并没有总结所有出现的内容。

我有什么事吗?

0 个答案:

没有答案