|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
代码试试看看:
Sub test()
Dim d, arr, brr
Set d = CreateObject("Scripting.Dictionary")
arr = Sheets("数据源").Range("A1").CurrentRegion
ReDim brr(1 To UBound(arr), 1 To 6)
For i = 2 To UBound(arr)
s = arr(i, 1) & arr(i, 2)
If d(s) = "" Then
m = m + 1
d(s) = m
brr(m, 1) = arr(i, 1)
brr(m, 2) = arr(i, 2)
' brr(m, 3) = arr(i, 3)
' brr(m, 4) = arr(i, 4)
brr(m, 5) = arr(i, 5)
brr(m, 6) = arr(i, 6)
Else
brr(d(s), 5) = brr(d(s), 5) + arr(i, 5)
brr(d(s), 6) = brr(d(s), 6) + arr(i, 6)
End If
Next
Sheets("生成表格").Range("a1:f1") = Array("编号", "品类", "名称", "单价", "数量", "合计")
Sheets("生成表格").Range("A2").Resize(m, 6) = brr
End Sub
|
|