|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
代码如下。。。
Sub test()
Dim wb As Workbook, sht As Worksheet
Set wb = ThisWorkbook
Set sht = wb.Sheets("区县汇总报表")
Set Rng = sht.[a2].CurrentRegion
Rng.Offset(2, 1).ClearContents
arr = Rng.Value
Set d = CreateObject("scripting.dictionary")
For i = 2 To UBound(arr, 2) Step 2
s = arr(1, i)
If Not d.exists(s) Then
d(s) = i
End If
Next
For Each sh In wb.Sheets
If InStr(sh.Name, "区县汇总报表") = 0 Then
r = sh.Cells(Rows.Count, 2).End(3).Row
c = sh.Cells(3, Columns.Count).End(1).Column
brr = sh.Range(sh.[a2], sh.Cells(r, c))
For i = 3 To UBound(brr, 2) Step 2
s = brr(1, i)
s = Mid(s, InStr(s, "-") + 1)
If d.exists(s) Then
m = d(s)
For k = 3 To UBound(arr)
arr(k, m) = arr(k, m) + brr(k, i)
arr(k, m + 1) = arr(k, m + 1) + brr(k, i + 1)
Next
End If
Next
End If
Next
Rng.Value = arr
Set d = Nothing
Beep
End Sub
|
|