|
Sub 拆分()
Application.ScreenUpdating = False
Dim d As Object, dc As Object, dic As Object
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
Set dic = CreateObject("scripting.dictionary")
Dim ar As Variant, br As Variant
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, 1).End(xlUp).Row
ar = .Range("a1:n" & r)
End With
For i = 3 To UBound(ar)
If Trim(ar(i, 3)) <> "" Then
dic(Trim(ar(i, 3))) = ""
End If
Next i
For Each k In dic.keys
n = 0: y = 5
dc.RemoveAll: d.RemoveAll
ReDim cr(1 To UBound(ar), 1 To UBound(ar, 2))
Sheets("模板").Copy after:=Sheets(Sheets.Count)
With Sheets(Sheets.Count)
.Name = k
br = .Range("a1:z24")
For i = 5 To UBound(br)
If Trim(br(i, 3)) <> "" Then
If InStr(br(i, 3), "组:") = 0 Then
d(Trim(br(i, 3))) = i
End If
End If
Next i
For i = 3 To UBound(ar)
If Trim(ar(i, 3)) = k Then
n = d(Trim(ar(i, 6)))
If n <> "" Then
If Not dc.exists(Trim(ar(i, 1))) Then
y = y + 4
br(n, y) = ar(i, 8)
br(2, y) = ar(i, 1)
dc(Trim(ar(i, 1))) = y
Else
m = dc(Trim(ar(i, 1)))
br(n, m) = br(n, m) + ar(i, 8)
End If
End If
End If
Next i
.Range("a1:z24") = br
.[a1] = "工单号:" & k
.[b5:b11] = k
.[b13:b21] = k
.[b23:b24] = k
End With
Next k
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|