|
Sub 拆分()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("总表")
r = .Cells(Rows.Count, 2).End(xlUp).Row
ar = .Range("a3:e" & r)
End With
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
d(ar(i, 2)) = ""
End If
Next i
For Each k In d.keys
n = 0
ReDim br(1 To UBound(ar), 1 To UBound(ar, 2))
For i = 2 To UBound(ar)
If ar(i, 2) = k Then
n = n + 1
br(n, 1) = n
For j = 3 To UBound(ar, 2)
br(n, j - 1) = ar(i, j)
Next j
End If
Next i
m = 0
With Sheets(k & "班")
rs = .Cells(Rows.Count, 2).End(xlUp).Row + 1
.Range("a4:e" & rs) = Empty
.Range("g4:k" & rs) = Empty
For i = 1 To n Step 35
m = m + 1
If m = 1 Then
xh = 1
Else
xh = 7
End If
w = 3
For s = i To i + 34
If s <= n Then
If br(s, 2) <> "" Then
w = w + 1
.Cells(w, xh).Resize(1, UBound(br, 2)) = Application.Index(br, s, 0)
End If
End If
Next s
Next i
End With
Next k
MsgBox "ok"
End Sub
|
|