- Sub lqxs()
- Dim Arr, myPath$, myName$, Brr, i&, j&, aa, ii&
- Dim x$, y$, k, t, kk, tt, bb
- Set d = CreateObject("Scripting.Dictionary")
- Application.ScreenUpdating = False
- Sheet1.Activate
- Cells.ClearContents
- myPath = ThisWorkbook.Path & "\成绩"
- myName = Dir(myPath & "*.xlsx")
- Do While myName <> ""
- With GetObject(myPath & myName)
- Arr = .Sheets(1).Range("A1").CurrentRegion
- For i = 2 To UBound(Arr)
- x = Arr(i, 1) & "," & Arr(i, 2): y = Arr(1, 3)
- If d.exists(x) = False Then Set d(x) = CreateObject("Scripting.Dictionary")
- d(x)(y) = Arr(i, 3)
- Next
- .Close False
- End With
- myName = Dir
- Loop
- k = d.keys: t = d.items
- ReDim Brr(1 To d.Count + 1, 1 To 20)
- Brr(1, 1) = "考号": Brr(1, 2) = "姓名"
- For i = 0 To UBound(k)
- kk = t(i).keys: tt = t(i).items
- bb = Split(k(i), ",")
- For ii = 0 To UBound(kk)
- Brr(i + 2, 1) = bb(0): Brr(i + 2, 2) = bb(1): Brr(i + 2, ii + 3) = tt(ii)
- If Brr(1, ii + 3) = "" Then Brr(1, ii + 3) = kk(ii)
- Next
- Next
- [a1].Resize(UBound(Brr), UBound(Brr, 2)) = Brr
- Application.ScreenUpdating = True
- End Sub
复制代码 |