|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Dim wb As Workbook
- Dim ws As Worksheet
- Dim mypath$, myname$
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- mypath = ThisWorkbook.Path & "\16科期考成绩"
- myname = Dir(mypath & "*.xlsx")
- n = 1
- Do While myname <> ""
- If myname <> ThisWorkbook.Name Then
- bj = Split(myname, "-")(0)
- n = n + 1
- d1(bj) = n
- Set wb = GetObject(mypath & myname)
- With wb
- With .Worksheets(1)
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a1").Resize(r, c)
- For i = 2 To UBound(arr)
- If Not d.exists(arr(i, 1)) Then
- Set d(arr(i, 1)) = CreateObject("scripting.dictionary")
- End If
- If Not d(arr(i, 1)).exists(bj) Then
- ReDim brr(1 To 4)
- Else
- brr = d(arr(i, 1))(bj)
- End If
- If Len(arr(i, c)) <> 0 Then
- brr(1) = brr(1) + 1
- brr(2) = brr(2) + arr(i, c)
- If arr(i, c) >= 80 Then
- brr(3) = brr(3) + 1
- End If
- If arr(i, c) >= 60 Then
- brr(4) = brr(4) + 1
- End If
- End If
- d(arr(i, 1))(bj) = brr
- Next
- End With
- .Close False
- End With
- End If
- myname = Dir
- Loop
- ls = 1 + d1.Count
- ReDim crr(1 To d.Count, 1 To ls)
- ReDim drr(1 To d.Count, 1 To ls)
- ReDim frr(1 To d.Count, 1 To ls)
- m = 0
- For Each aa In d.keys
- m = m + 1
- crr(m, 1) = aa
- drr(m, 1) = aa
- frr(m, 1) = aa
- For Each bb In d(aa).keys
- brr = d(aa)(bb)
- n = d1(bb)
- If Len(brr(1)) <> 0 And brr(1) <> 0 Then
- crr(m, n) = Application.Round(brr(2) / brr(1), 2)
- drr(m, n) = Application.Round(brr(3) / brr(1), 4)
- frr(m, n) = Application.Round(brr(4) / brr(1), 4)
- End If
- Next
- Next
- With Worksheets("各校各级各科平均分")
- .UsedRange.Offset(1, 0).Clear
- With .Range("a1")
- .UnMerge
- .Resize(1, ls).Merge
- End With
- .Range("a2") = "学校"
- .Range("b2").Resize(1, d1.Count) = d1.keys
- .Range("a3").Resize(UBound(crr), UBound(crr, 2)) = crr
- With .Range("a2").Resize(1 + UBound(crr), UBound(crr, 2))
- .Borders.LineStyle = xlContinuous
- With .Font
- .Name = "微软雅黑"
- .Size = 11
- End With
- End With
- With .UsedRange
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- With Worksheets("各校各级各科优秀率")
- With .Range("a1")
- .UnMerge
- .Resize(1, ls).Merge
- End With
- .UsedRange.Offset(1, 0).Clear
- .Range("a2") = "学校"
- .Range("b2").Resize(1, d1.Count) = d1.keys
- .Range("a3").Resize(UBound(drr), UBound(drr, 2)) = drr
- .Range("b3").Resize(UBound(drr), UBound(drr, 2) - 1).NumberFormatLocal = "0.00%"
- With .Range("a2").Resize(1 + UBound(drr), UBound(drr, 2))
- .Borders.LineStyle = xlContinuous
- With .Font
- .Name = "微软雅黑"
- .Size = 11
- End With
- End With
- With .UsedRange
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- With Worksheets("各校各级各科及格率")
- With .Range("a1")
- .UnMerge
- .Resize(1, ls).Merge
- End With
- .UsedRange.Offset(1, 0).Clear
- .Range("a2") = "学校"
- .Range("b2").Resize(1, d1.Count) = d1.keys
- .Range("a3").Resize(UBound(frr), UBound(frr, 2)) = frr
- .Range("b3").Resize(UBound(frr), UBound(frr, 2) - 1).NumberFormatLocal = "0.00%"
- With .Range("a2").Resize(1 + UBound(frr), UBound(frr, 2))
- .Borders.LineStyle = xlContinuous
- With .Font
- .Name = "微软雅黑"
- .Size = 11
- End With
- End With
- With .UsedRange
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|