|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 拆分()
Application.ScreenUpdating = False
Dim ar As Variant
Dim i As Long
Dim br()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
Application.DisplayAlerts = False
For Each sh In Sheets
If sh.Index > 2 Then sh.Delete
Next sh
Application.DisplayAlerts = True
With Sheets("原始数据")
r = .Cells(Rows.Count, 12).End(xlUp).Row
ar = .Range("a1:ad" & r)
End With
For i = 2 To UBound(ar)
If Trim(ar(i, 12)) <> "" Then
d(Trim(ar(i, 12))) = ""
End If
Next i
For Each k In d.keys
n = 0
ReDim br(1 To UBound(ar), 1 To 13)
For i = 2 To UBound(ar)
If Trim(ar(i, 12)) = k Then
zd = Trim(ar(i, 14)) & "|" & Trim(ar(i, 15)) & "|" & Trim(ar(i, 17))
t = d(zd)
If t = "" Then
n = n + 1
d(zd) = n
t = n
For j = 14 To 16
br(n, j - 13) = ar(i, j)
Next j
br(n, 5) = ar(i, 30)
br(n, 6) = ar(i, 17)
br(n, 7) = ar(i, 19)
br(n, 8) = ar(i, 20)
br(n, 9) = ar(i, 23)
br(n, 11) = ar(i, 29)
br(n, 12) = ar(i, 28)
br(n, 13) = ar(i, 26)
End If
br(t, 4) = br(t, 4) + ar(i, 18)
br(t, 10) = br(t, 10) + ar(i, 23)
End If
Next i
Sheets("模板").Copy after:=Sheets(Sheets.Count)
With ActiveSheet
.Name = k
.[A1] = k
.[a4].Resize(n, UBound(br, 2)) = br
.Rows(n + 4 & ":35").Delete
End With
Next k
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
评分
-
1
查看全部评分
-
|