|
为便于截图和察看,把AB两表合一块了,右上角的表格是汇总的数据,看可符合的你的意思?
- Sub 根据姓名汇总()
- Dim ar, br, i&, r&, dic As Object
-
- Set dic = CreateObject("Scripting.Dictionary")
- With Sheets("B表").[A1].CurrentRegion
- br = .Cells.Value
- r = .Rows.Count
- End With
- For i = 2 To r: dic(br(i, 2)) = dic(br(i, 2)) + br(i, 3): Next i
-
- ar = Sheets("A表").[A2].CurrentRegion
- For i = 2 To UBound(ar)
- If dic.exists(ar(i, 2)) Then
- ar(i, 3) = dic(ar(i, 2))
- Else
- ar(i, 3) = 0
- End If
- Next i
- ar(1, 3) = "梨数量汇总"
- Sheets("A表").[A1].CurrentRegion.Offset(0, 5) = ar
- Set dic = Nothing
- End Sub
复制代码
|
|