|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Dim wb As Workbook
- Dim ws As Worksheet
- Dim mypath$, myname$
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- mypath = ThisWorkbook.Path & ""
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- .Range("c2").Resize(r - 1, c - 2).ClearContents
- arr = .Range("a1").Resize(r, c)
- End With
- For i = 2 To UBound(arr)
- d(CStr(arr(i, 2))) = i
- Next
- For j = 7 To UBound(arr, 2)
- If Dir(mypath & arr(1, j) & "成绩.xls") <> "" Then
- Set wb = GetObject(mypath & arr(1, j) & "成绩.xls")
- With wb
- With .Worksheets(1)
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- brr = .Range("a4:q" & r)
- For i = 1 To UBound(brr)
- If d.exists(CStr(brr(i, 2))) Then
- m = d(CStr(brr(i, 2)))
- If j = 7 Then
- For k = 3 To 6
- arr(m, k) = brr(i, k)
- Next
- End If
- arr(m, j) = brr(i, 7)
- End If
- Next
- End With
- .Close False
- End With
- End If
- Next
- For j = 7 To UBound(arr, 2) Step 2
- d.RemoveAll
- For i = 2 To UBound(arr)
- If Len(arr(i, j)) <> 0 Then
- d(arr(i, j)) = d(arr(i, j)) + 1
- End If
- Next
- nn = 1
- kk = d.keys
- For k = 0 To UBound(kk)
- mm = Application.Large(kk, k + 1)
- ss = d(mm)
- d(mm) = nn
- nn = nn + ss
- Next
- For i = 2 To UBound(arr)
- If Len(arr(i, j)) <> 0 Then
- arr(i, j + 1) = d(arr(i, j))
- End If
- Next
- Next
- With Worksheets("sheet1")
- .Range("a1").Resize(UBound(arr), UBound(arr, 2)) = arr
- For i = 2 To UBound(arr)
- For j = 7 To UBound(arr, 2)
- If Len(arr(i, j)) = 0 Then
- With .Cells(i, j)
- .Value = "缺考"
- .Interior.ColorIndex = 6
- End With
- End If
- Next
- Next
- End With
- End Sub
复制代码 |
|