|
Sub 拆分()
Application.ScreenUpdating = False
Dim ar As Variant
Dim arr()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("数据")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 3 Then MsgBox "数据为空!": End
ar = .Range("a2:h" & r)
End With
For i = 2 To UBound(ar)
If Trim(ar(i, 3)) <> "" Then
d(Trim(ar(i, 3))) = ""
End If
Next i
With Sheets("确认签字")
rs = .Cells(Rows.Count, 8).End(xlUp).Row
If rs > 37 Then .Rows("38:" & rs).Delete
.Range("b4:d36") = Empty
.Range("h4:j36") = Empty
gs = d.Count
m = 38
For i = 1 To gs - 1
.Rows("1:37").Copy .Cells(m, 1)
m = m + 37
Next i
m = 4
For Each k In d.keys
n = 0: tt = 0
ReDim arr(1 To UBound(ar), 1 To 3)
For i = 2 To UBound(ar)
If Trim(ar(i, 3)) = k Then
n = n + 1
For j = 2 To 4
arr(n, j - 1) = ar(i, j)
Next j
End If
Next i
.Cells(m - 2, 2) = "总人数:" & n
If n <= 33 Then
.Cells(m, 2).Resize(n, 3) = arr
Else
For i = 1 To n Step 33
tt = tt + 1
xh = m - 1
If tt = 1 Then
lh = 2
Else
lh = 8
End If
For s = i To i + 32
If s <= n Then
xh = xh + 1
.Cells(xh, lh).Resize(1, 3) = Application.Index(arr, s, 0)
End If
Next s
Next i
End If
m = m + 37
Next k
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|