|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 拆分()
Application.ScreenUpdating = False
Dim ar As Variant
Dim i As Long, r As Long, rs As Long
Dim br()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("数据表")
r = .Cells(Rows.Count, 2).End(xlUp).Row
If r < 3 Then MsgBox "数据表为空!": End
ar = .Range(.Cells(2, 1), .Cells(r, 9))
End With
Application.DisplayAlerts = False
For Each sh In Sheets
If sh.Index > 2 Then
sh.Delete
End If
Next sh
Application.DisplayAlerts = True
For i = 2 To UBound(ar)
If ar(i, 1) <> "" Then
If InStr(ar(i, 1), "汇总") = 0 Then
If d(ar(i, 1)) = "" Then
d(ar(i, 1)) = i
Else
d(ar(i, 1)) = d(ar(i, 1)) & "|" & i
End If
End If
End If
Next i
For Each k In d.keys
rr = Split(d(k), "|")
n = 0: hj = 0
ReDim br(1 To UBound(ar), 1 To 12)
For i = 0 To UBound(rr)
xh = rr(i)
n = n + 1
br(n, 1) = n
br(n, 2) = ar(xh, 2)
br(n, 3) = ar(xh, 6)
br(n, 4) = ar(xh, 5)
br(n, 5) = ar(xh, 7)
br(n, 6) = ar(xh, 9)
br(n, 11) = k
br(n, 12) = "冯威"
hj = hj + ar(xh, 9)
Next i
Sheets("模板").Copy after:=Sheets(Sheets.Count)
With ActiveSheet
.Name = k
.[a3].Resize(n, UBound(br, 2)) = br
.[f246] = hj
ws = n + 3
If ws <= 245 Then .Rows(ws & ":245").Delete
End With
Next k
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|