学习也要有个循序渐进的过程。初学者对字典知识一下子搞懂恐怕有点难:
- Sub gj23w98()
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- With Sheets("台账")
- r = .Cells(.Rows.Count, 1).End(3).Row
- arr = .Range("a2:o" & r)
- For i = 2 To UBound(arr)
- If arr(i, 1) = "p" Then
- d(arr(i, 4)) = d(arr(i, 4)) + arr(i, 15)
- End If
- If arr(i, 1) = "f" Then
- d1(arr(i, 4)) = d1(arr(i, 4)) + arr(i, 15)
- End If
- Next
- End With
- With Sheets("供应商账务汇总")
- r = .Cells(.Rows.Count, 2).End(3).Row
- .Range("d3:o" & r).ClearContents
- For i = 3 To r
- If d.exists(.Cells(i, 2).Value) Then
- .Cells(i, 4) = d(.Cells(i, 2).Value)
- .Cells(i, 5) = d1(.Cells(i, 2).Value)
- End If
- Next
- End With
- End Sub
复制代码 |