|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
首先请务必统一汇总表的M列与各分表完全相同,比如不要简称全称混用,比如工作表“马山县林圩镇隆胜养专业合作社”就少了个“殖”字。
- Sub test()
- Set d = CreateObject("Scripting.Dictionary")
- For i = 4 To Sheets.Count
- d(Sheets(i).Name) = ""
- Next
- arr = Sheets("汇总").UsedRange
- For i = 2 To UBound(arr)
- s = arr(i, 13)
- If d.exists(s) Then
- With Sheets(s)
- r = .Cells(Rows.Count, 1).End(3).Row
- For j = r To 2 Step -1
- If .Cells(j, 1) = Int(arr(i, 19)) Then
- If .Cells(j, 3) = "" Then
- .Cells(j, 3) = arr(i, 1)
- .Cells(j, 4) = arr(i, 19)
- Else
- .Rows(j).Insert
- .Cells(j, 1) = .Cells(j + 1, 1)
- .Cells(j, 3) = arr(i, 1)
- .Cells(j, 4) = arr(i, 19)
- End If
- End If
- Next
- End With
- Else
- MsgBox "找不到" & s
- End If
- Next
- End Sub
复制代码 |
|