|
'顶老师一下吧,这里以 学籍号 为唯一值判断。
Option Explicit
Sub StudentAndTeacher() '学生数 或 老师数 不可超过 49 人,多了 不中!!!
Dim Cn As Object, d As Object, p$, f$, s$(2), t$(2), ar, br, i&, j&, k&, y&
For i = 1 To Sheets.Count
Sheets(i).UsedRange.Offset(1).ClearContents
Next
Set Cn = CreateObject("ADODB.Connection")
Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
s(0) = "SELECT 序号,学籍号,性别,班级,姓名,学业水平,身心健康,艺术素养,社会实践,评价类型"
p = ThisWorkbook.Path & "\student\"
f = Dir(p & "*.xls*")
Do While f <> ""
s(1) = s(1) & " UNION ALL SELECT * FROM [" & p & f & "].[$A1:J]"
f = Dir
Loop
s(2) = Mid(s(1), 11)
s(1) = s(0) & " FROM (" & s(2) & ") WHERE 评价类型='自评' ORDER BY 学籍号"
With Sheets("自评")
.Range("A2").CopyFromRecordset Cn.Execute(s(1))
t(0) = " FROM [" & .Name & "$A1:I" & .Cells(Rows.Count, 2).End(xlUp).Row & "] GROUP BY 学籍号"
t(0) = "SELECT 学籍号,AVG(学业水平)*0.1,AVG(身心健康)*0.1,AVG(艺术素养)*0.1,AVG(社会实践)*0.1" & t(0)
br = .Range("A1:I" & .Cells(Rows.Count, 2).End(xlUp).Row)
End With
s(1) = s(0) & " FROM (" & s(2) & ") WHERE 评价类型='互评' ORDER BY 学籍号"
With Sheets("互评")
.Range("A2").CopyFromRecordset Cn.Execute(s(1))
t(1) = " FROM [" & .Name & "$A1:I" & .Cells(Rows.Count, 2).End(xlUp).Row & "] GROUP BY 学籍号"
t(1) = "SELECT 学籍号,AVG(学业水平)*0.5,AVG(身心健康)*0.5,AVG(艺术素养)*0.5,AVG(社会实践)*0.5" & t(1)
End With
s(1) = ""
p = ThisWorkbook.Path & "\teacher\"
f = Dir(p & "*.xls*")
Do While f <> ""
s(1) = s(1) & " UNION ALL SELECT * FROM [" & p & f & "].[$A1:J]"
f = Dir
Loop
s(2) = Mid(s(1), 11)
s(1) = s(0) & " FROM (" & s(2) & ") WHERE 评价类型='教师评' ORDER BY 学籍号"
With Sheets("教师评")
.Range("A2").CopyFromRecordset Cn.Execute(s(1))
t(2) = " FROM [" & .Name & "$A1:I" & .Cells(Rows.Count, 2).End(xlUp).Row & "] GROUP BY 学籍号"
t(2) = "SELECT 学籍号,AVG(学业水平)*0.4,AVG(身心健康)*0.4,AVG(艺术素养)*0.4,AVG(社会实践)*0.4" & t(2)
s(1) = "SELECT DISTINCT 学籍号,性别,班级,姓名 FROM [" & .Name & "$A1:E" & .Cells(Rows.Count, 3).End(xlUp).Row & "] ORDER BY 学籍号"
End With
Set d = CreateObject("Scripting.Dictionary")
With Sheets("民主评议汇总")
.Range("B2").CopyFromRecordset Cn.Execute(s(1))
ar = .Range("A1:I" & .Cells(Rows.Count, 2).End(xlUp).Row)
For i = 2 To UBound(ar)
d(CStr(ar(i, 2))) = i
Next
For k = 0 To UBound(t)
br = Cn.Execute(t(k)).GetRows
For j = 0 To UBound(br, 2)
If d.Exists(CStr(br(0, j))) Then
y = d(CStr(br(0, j)))
For i = 1 To 4
ar(y, i + 5) = ar(y, i + 5) + br(i, j)
Next
End If
Next
Next
.Range("A1:I" & .Cells(Rows.Count, 2).End(xlUp).Row) = ar
End With
Cn.Close
Set Cn = Nothing
Set d = Nothing
End Sub |
评分
-
1
查看全部评分
-
|