|
Sub 分班()
Application.ScreenUpdating = False
Dim ar As Variant, br As Variant
Dim d As Object, dc As Object
Dim arr(), brr()
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
With Sheets("汇总表")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 3 Then MsgBox "数据源为空!": End
ar = .Range("a1:n" & r)
rs = .Cells(Rows.Count, 19).End(xlUp).Row
If rs < 3 Then MsgBox "班主任信息为空!": End
br = .Range("s1:t" & r)
rq = Format(.[q1], "yyyy年m月d日")
End With
For i = 2 To UBound(br)
If Trim(br(i, 1)) <> "" Then
dc(Trim(br(i, 1))) = br(i, 2)
End If
Next i
For i = 3 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
d(Trim(ar(i, 1))) = ""
End If
Next i
For Each k In d.keys
n = 0: m = 0
ReDim arr(1 To UBound(ar), 1 To UBound(ar, 2))
ReDim brr(1 To UBound(ar), 1 To UBound(ar, 2))
For i = 3 To UBound(ar)
If Trim(ar(i, 1)) = k Then
n = n + 1
If n <= 31 Then
For j = 1 To UBound(ar, 2)
arr(n, j) = ar(i, j)
Next j
Else
m = m + 1
For j = 1 To UBound(ar, 2)
brr(m, j) = ar(i, j)
Next j
End If
End If
Next i
Sheets("各班调查表").Copy
Set wb = ActiveWorkbook
With wb.Worksheets(1)
.Name = k & "班"
.[a2] = "排查时间: " & rq & " 班主任(签名): " & dc(k)
.[a38] = "排查时间: " & rq & " 班主任(签名): " & dc(k)
.[a6].Resize(31, UBound(arr, 2)) = arr
If m > 0 Then .[a42].Resize(m, UBound(brr, 2)) = brr
For j = 3 To 14
For i = 1 To n
If arr(i, j) = "√" Then
.Cells(71, j) = .Cells(71, j) + 1
End If
Next i
Next j
For j = 3 To 14
For i = 1 To m
If brr(i, j) = "√" Then
.Cells(71, j) = .Cells(71, j) + 1
End If
Next i
Next j
End With
wb.SaveAs Filename:=ThisWorkbook.Path & "\" & k & "班防溺水调查表.xlsx"
wb.Close
Next k
Set d = Nothing
Set dc = Nothing
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|