|
Sub a()
Dim sh As Worksheet
Application.DisplayAlerts = False
Application.ScreenUpdating = False
For Each sh In Sheets
If sh.Name <> "总表" Then
sh.Delete
End If
Next
Dim cnn, cnn1, rs, rs1, Sqa$, bt, j%, m%, sqb$, arr
bt = [{"姓名","班级","总分","总分排名","总分班级排名"}]
Set cnn = CreateObject("adodb.connection")
Set cnn1 = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.Recordset")
Set rs1 = CreateObject("adodb.Recordset")
cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & ThisWorkbook.FullName
cnn1.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & ThisWorkbook.FullName
Sqa = "select distinct 班级,COUNT(*) from [总表$b1:b] where 班级 is not null GROUP BY 班级"
rs.Open Sqa, cnn, 1, 1
Do While Not rs.EOF
Sheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = rs.Fields(0)
[a1:j1].Merge
[a1] = rs.Fields(0) & "成绩表"
[a1].HorizontalAlignment = xlCenter
[a2] = rs.Fields(0) & "班主任"
sqb = "select * from [总表$a1:e] where 班级='" & rs.Fields(0) & "'"
rs1.Open sqb, cnn1, 1, 1
For j = 0 To Round(rs.Fields(1) / 30 + 0.49, 0) - 1
[a3].Offset(0, j * 5).Resize(1, 5) = bt
arr = Application.Transpose(rs1.getRows(30, 0))
[a4].Offset(0, j * 5).Resize(UBound(arr), 5) = arr
[a3].Offset(0, j * 5).Resize(UBound(arr) + 1, 5).Borders.LineStyle = 1
Next
rs1.Close
rs.MoveNext
Loop
Set rs = Nothing
Set cnn = Nothing
Set rs1 = Nothing
Set cnn1 = Nothing
Application.ScreenUpdating = True
End Sub |
评分
-
1
查看全部评分
-
|