|
Sub 批量生成()
Application.ScreenUpdating = False
With Sheets("报名表")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "报名表为空!": End
ar = .Range("a2:d" & r)
End With
hs = UBound(ar) - 1
If hs / 24 = Int(hs / 24) Then
gs = hs / 24
Else
gs = Int(hs / 24) + 1
End If
With Sheets("模板")
.Range("b6:f17") = Empty
.Range("h6:l17") = Empty
rs = .Cells(Rows.Count, 1).End(xlUp).Row
If rs > 18 Then .Rows("19:" & rs).Delete
m = 19
For i = 2 To gs
.Rows("1:18").Copy .Cells(m, 1)
m = m + 18
Next i
m = 5
For i = 2 To UBound(ar) Step 24
xh = m
For s = i To i + 11 Step 1
If s <= UBound(ar) Then
xh = xh + 1
.Cells(xh, 2) = ar(s, 2)
.Cells(xh, 3) = ar(s, 3)
End If
Next s
xh = m
For s = i + 12 To i + 23 Step 1
If s <= UBound(ar) Then
xh = xh + 1
.Cells(xh, 8) = ar(s, 2)
.Cells(xh, 9) = ar(s, 3)
End If
Next s
m = m + 18
Next i
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|