|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Randomize Timer
- rs = Application.InputBox(prompt:="请输入每个考室人数", Title:="操作提示", Default:=30, Type:=1)
- If rs = False Then
- MsgBox "没有输入考室人数!"
- Exit Sub
- End If
- With Worksheets("学生信息")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:g" & r)
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 7)) Then
- Set d(arr(i, 7)) = CreateObject("scripting.dictionary")
- End If
- If Not d(arr(i, 7)).exists(arr(i, 1)) Then
- Set d(arr(i, 7))(arr(i, 1)) = CreateObject("scripting.dictionary")
- End If
- d(arr(i, 7))(arr(i, 1))(i) = ""
- Next
- ReDim brr(1 To UBound(arr), 1 To 3)
- For Each aa In d.keys
- For Each bb In d(aa).keys
- m = 1
- n = 1
- kk = d(aa)(bb).keys
- For i = 0 To UBound(kk) - 1
- x = Int((UBound(kk) - i) * Rnd()) + i + 1
- temp = kk(i)
- kk(i) = kk(x)
- kk(x) = temp
- Next
- For i = 0 To UBound(kk)
- brr(kk(i), 1) = m
- brr(kk(i), 2) = n
- brr(kk(i), 3) = arr(kk(i), 1) & arr(kk(i), 2) & arr(kk(i), 4) & arr(kk(i), 5) & arr(kk(i), 6) & Format(m, "00") & Format(n, "00")
- n = n + 1
- If n > rs Then
- m = m + 1
- n = 1
- End If
- Next
- Next
- Next
- .Columns(10).NumberFormatLocal = "@"
- .Range("h2").Resize(UBound(brr), UBound(brr, 2)) = brr
-
- End With
- End Sub
复制代码 |
评分
-
3
查看全部评分
-
|