|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Explicit
Sub test()
Dim arr(1), i, j, k, dic, n
Set dic = CreateObject("scripting.dictionary")
Call getdatatoarr(arr, 0, "数据表1", "ah4", 6)
Call getdatatoarr(arr, 1, "数据表2", "aq2", 6)
ReDim brr(1 To UBound(arr(0), 1) + UBound(arr(1), 1), 1 To 6)
For i = 0 To UBound(arr)
For j = 1 To UBound(arr(i), 1)
If dic.exists(arr(i)(j, 2)) Then
brr(dic(arr(i)(j, 2)), 6) = brr(dic(arr(i)(j, 2)), 6) + arr(i)(j, 6)
brr(dic(arr(i)(j, 2)), 3) = brr(dic(arr(i)(j, 2)), 3) + arr(i)(j, 3)
Else
n = n + 1
For k = 1 To UBound(arr(i), 2): brr(n, k) = arr(i)(j, k): Next
dic(arr(i)(j, 2)) = n
End If
Next j, i
With Sheets("数据表1").[as4]
.Resize(Rows.Count - 3, UBound(brr, 2)).ClearContents
.Resize(n, 6) = brr
End With
End Sub
Function getdatatoarr(arr, i, sht, pos, n)
With Sheets(sht)
arr(i) = .Range(pos).Resize(.Cells(Rows.Count, .Range(pos).Column).End(xlUp).Row, n)
End With
End Function |
|