- Sub test()
- Dim r%, i%, n(1 To 3) As Byte
- Dim arr, brr, crr(1 To 10000, 1 To 10)
- Dim mypath$, myname$
- Dim wb As Workbook
- Dim ws As Worksheet
- Dim d As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- With Worksheets("汇总")
- r = .Cells(.Rows.Count, 2).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- .Range("g2").Resize(r - 1, c - 6).ClearContents
- brr = .Range("a1").Resize(r, c)
- For i = 2 To UBound(brr)
- xm = brr(i, 2) & "+" & brr(i, 4)
- d(xm) = i
- For j = 7 To UBound(brr, 2)
- Set brr(i, j) = CreateObject("scripting.dictionary")
- Next
- Next
- End With
- x = 0
- For j = 7 To UBound(brr, 2)
- If Dir(ThisWorkbook.Path & "" & brr(1, j) & ".xls") <> "" Then
- Set wb = GetObject(ThisWorkbook.Path & "" & brr(1, j) & ".xls")
- With wb
- For Each ws In .Worksheets
- With ws
- If Not d1.exists(brr(1, j)) Then
- Set d1(brr(1, j)) = CreateObject("scripting.dictionary")
- End If
- d1(brr(1, j))(ws.Name) = Empty
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a1").Resize(r, c)
- Erase n
- For k = 1 To UBound(arr, 2)
- If arr(1, k) = "班级" Then
- n(1) = k
- ElseIf arr(1, k) = "姓名" Then
- n(2) = k
- ElseIf arr(1, k) = "分数" Then
- n(3) = k
- End If
- Next
- If n(1) * n(2) * n(3) <> 0 Then
- For i = 2 To UBound(arr)
- xm = arr(i, n(1)) & "+" & arr(i, n(2))
- If d.exists(xm) Then
- m = d(xm)
- brr(m, j)(ws.Name) = arr(i, n(3))
- x = x + 1
- crr(x, 1) = x
- crr(x, 2) = Empty
- crr(x, 3) = arr(i, n(1))
- crr(x, 4) = Empty
- crr(x, 5) = arr(i, n(2))
- crr(x, 8) = brr(1, j)
- crr(x, 9) = ws.Name
- crr(x, 10) = "分数空白"
- End If
- Next
- End If
- End With
- Next
- .Close False
- End With
- End If
- Next
- x = 0
- For j = 7 To UBound(brr, 2)
- For i = 2 To UBound(brr)
- If d1.exists(brr(1, j)) Then
- ss = 0
- For Each bb In d1(brr(1, j)).keys
- If brr(i, j).exists(bb) Then
- If brr(i, j)(bb) <> Empty Then
- ss = ss + brr(i, j)(bb)
- Else
- x = x + 1
- crr(x, 1) = x
- crr(x, 2) = Empty
- crr(x, 3) = brr(i, 2)
- crr(x, 4) = Empty
- crr(x, 5) = brr(i, 4)
- crr(x, 8) = brr(1, j)
- crr(x, 9) = bb
- crr(x, 10) = "分数空白"
- End If
- Else
- x = x + 1
- crr(x, 1) = x
- crr(x, 2) = Empty
- crr(x, 3) = brr(i, 2)
- crr(x, 4) = Empty
- crr(x, 5) = brr(i, 4)
- crr(x, 8) = brr(1, j)
- crr(x, 9) = bb
- crr(x, 10) = "无记录"
- End If
- Next
- brr(i, j) = ss
- Else
- brr(i, j) = Empty
- End If
- Next
- Next
- With Worksheets("汇总")
- .Range("a1").Resize(UBound(brr), UBound(brr, 2)) = brr
- End With
- With Worksheets("问题")
- .UsedRange.Offset(1, 0).Clear
- If x > 0 Then
- .Range("a2").Resize(x, UBound(crr, 2)) = crr
- End If
- End With
- End Sub
复制代码 |