|
本帖最后由 feiren228 于 2014-12-24 13:16 编辑
- Sub 生成座次表() 'by feiren228
- Application.DisplayAlerts = False '不提示
- Application.ScreenUpdating = False '不刷新
- With Sheets("考生信息")
- Row1 = .Range("a" & .Rows.Count).End(xlUp).Row '考生信息的最后一行行号
- ks = .Range("a2:e" & Row1) '考生信息赋予数组
- End With
- With Sheets("考场信息") '同上考场信息赋予数组
- Row2 = .Range("a" & .Rows.Count).End(xlUp).Row
- kc = .Range("a2:c" & Row2)
- End With
- For Each sht In Sheets '扫描每一个工作表
- If sht.Name Like "试场*" Then '是考场工作表就删除
- sht.Delete
- End If
- Next
- For n = 1 To UBound(kc)
- k = Int(kc(n, 2) / 4)
- k0 = kc(n, 2) Mod 4
- ps = Array(k, k, k, k)
- For x = 0 To k0 - 1
- ps(x) = ps(x) + 1
- Next
- c0 = ps(0): c1 = ps(1): c2 = ps(2): c3 = ps(3)
- ReDim tempar(1 To ps(0), 1 To 12)
- For i = 1 To UBound(ks)
- If ks(i, 3) = kc(n, 1) Then
- m = m + 1
- Select Case m
- Case Is <= c0
- tempar(m, 1) = (ks(i, 1))
- tempar(m, 2) = (ks(i, 2))
- tempar(m, 3) = (ks(i, 4))
- Case Is <= c0 + c1
- tempar(ps(1), 4) = (ks(i, 1))
- tempar(ps(1), 5) = (ks(i, 2))
- tempar(ps(1), 6) = (ks(i, 4))
- ps(1) = ps(1) - 1
- Case Is <= c0 + c1 + c2
- y = y + 1
- tempar(y, 7) = (ks(i, 1))
- tempar(y, 8) = (ks(i, 2))
- tempar(y, 9) = (ks(i, 4))
- Case Is <= c0 + c1 + c2 + c3
- tempar(ps(3), 10) = (ks(i, 1))
- tempar(ps(3), 11) = (ks(i, 2))
- tempar(ps(3), 12) = (ks(i, 4))
- ps(3) = ps(3) - 1
- End Select
- End If
- Next i
- Sheets("座次表").Copy after:=Sheets(Sheets.Count) '复制“座次表”到最后
- With Sheets(Sheets.Count) '针对最后一个工作表
- .Name = "试场" & n '更名
- .Range("A5").Resize(UBound(tempar), 12) = tempar
- Erase tempar
- '.Range("D5:F" & ps(1) + 4).Sort key1:=[F4], Order1:=xlDescending
- ' .Range("J5:L" & ps(3) + 4).Sort key1:=[L4], Order1:=xlDescending
- ' .Range("G5:I" & ps(2) + 4).Sort key1:=[I4], Order1:=xlAscending
- .[F1] = n
- .[c2] = kc(n, 3)
- .[I2] = [A5] & "至" & [J5]
- End With
- m = 0: y = 0
- Next n
- Application.DisplayAlerts = True '恢复提示
- Application.ScreenUpdating = True '恢复刷屏
- End Sub
复制代码
|
|