|
楼主 |
发表于 2020-7-23 11:20
|
显示全部楼层
Sub 班级不相连安排考场()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim r As Integer
Dim i%
Dim arr As Variant, brr As Variant
Dim d As Object, dc As Object
Dim br()
Dim rng As Range
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
With Sheets("设置")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
If rs < 9 Then MsgBox "请先设置考场号和考场人数!": Exit Sub
y = .Cells(8, Columns.Count).End(xlToLeft).Column
rr = .Range(.Cells(8, 1), .Cells(rs, y))
End With
For Each sh In Sheets
If sh.Name <> "设置" And sh.Name <> "考生数据库" And sh.Name <> "桌贴模板" And sh.Name <> "准考证模板" And sh.Name <> "门贴" Then
sh.Delete
End If
Next sh
With Sheets("考生数据库")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "考生数据为空!": Exit Sub
brr = .[a1].CurrentRegion
End With
For i = 2 To UBound(brr)
If Trim(brr(i, 2)) <> "" Then
d(Trim(brr(i, 2))) = ""
End If
Next i
For Each K In d.keys
n = 0: a = 0
dc.RemoveAll
ReDim br(1 To UBound(brr), 1 To 7)
For i = 2 To UBound(brr)
If Trim(brr(i, 2)) = K Then
n = n + 1
For j = 2 To 4
br(n, j - 1) = brr(i, j)
Next j
End If
Next i
Set sht = Sheets.Add(after:=Sheets(Sheets.Count))
With Sheets(Sheets.Count)
.Name = K
.[a1].Resize(1, 7) = Array("年级", "班级", "姓名", "考场位置", "考号", "考场号", "座位号")
.[a2].Resize(n, UBound(br, 2)) = br
.Range("a1").Resize(n, UBound(br, 2)).Sort .[a1], 1, , , , , , 1 '按班级排序
.[a2].Resize(n, UBound(br, 2)).Borders.LineStyle = 1
arr = .[a2].Resize(n, UBound(br, 2))
nn = 0
For i = 1 To UBound(arr)
If Not dc.exists(arr(i, 2)) Then
nn = nn + 1
dc(arr(i, 2)) = nn
End If
Next i
For i = 1 To UBound(arr)
arr(i, 5) = d(arr(i, 2))
d(arr(i, 2)) = d(arr(i, 2)) + d.Count
Next
For i = 1 To UBound(arr)
For s = i + 1 To UBound(arr)
If arr(i, 5) > arr(s, 5) Then
For j = 1 To UBound(arr, 2)
Kk = arr(i, j)
arr(i, j) = arr(s, j)
arr(s, j) = Kk
Next j
End If
Next s
Next i
Set rng = Sheets("设置").Rows(8).Find(K, , , 1)
If rng Is Nothing Then MsgBox "设置中没有" & K & "年级的信息": Exit Sub
ws = rng.Column
For s = 2 To UBound(rr)
If Trim(rr(s, ws)) <> "" Then
For y = 1 To rr(s, ws)
a = a + 1
arr(a, 4) = rr(s, 2)
arr(a, 6) = Format(rr(s, 1), "000")
arr(a, 7) = Format(y, "00")
arr(a, 5) = Format(rr(s, 1), "00") & Format(y, "00")
Next y
End If
Next s
.Columns("E:G").NumberFormatLocal = "@"
.[a2].Resize(n, UBound(br, 2)) = arr
End With
Next K
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "ok!"'
End Sub
|
|