|
参与一下。。。- Sub ykcbf() '//2024.1.4
- Dim arr, brr, d
- Application.ScreenUpdating = False
- Set Fso = CreateObject("Scripting.FileSystemObject")
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- p = ThisWorkbook.Path & ""
- p1 = p & "Mh"
- f = p1 & "合并表.xlsx"
- Set ws = Workbooks.Open(f, 0)
- Set sh = ws.Sheets("合并表")
- On Error Resume Next
- For Each f In Fso.GetFolder(p1).Files
- If f.Name Like "*.xls*" Then
- If InStr(f.Name, "合并表") = 0 Then
- fn = Fso.GetBaseName(f)
- Set wb = Workbooks.Open(f, 0)
- With wb.Sheets(1)
- arr = .UsedRange
- wb.Close False
- End With
- For j = 1 To UBound(arr, 2)
- If arr(i, 1) <> Empty Then
- s = arr(1, j)
- d1(s) = s
- End If
- Next
- For i = 2 To UBound(arr)
- s = arr(i, 1)
- If s <> Empty Then
- If Not d.exists(s) Then Set d(s) = CreateObject("Scripting.Dictionary")
- For j = 1 To UBound(arr, 2)
- ss = arr(1, j)
- d(s)(ss) = d(s)(ss) + arr(i, j)
- Next
- End If
- Next
- End If
- End If
- Next
- ReDim zrr(1 To d.Count, 1 To 1)
- For Each k In d.keys
- n = n + 1
- zrr(n, 1) = k
- Next
- With sh
- .UsedRange = ""
- .[a1].Resize(1, d1.Count) = d1.keys
- .[a2].Resize(n, 1) = zrr
- arr = .UsedRange
- For i = 2 To UBound(arr)
- If arr(i, 1) <> Empty Then
- For j = 2 To UBound(arr, 1)
- If d.exists(arr(i, 1)) Then
- arr(i, j) = d(arr(i, 1))(arr(1, j))
- End If
- Next
- End If
- Next
- .UsedRange = arr
- With .UsedRange
- .Value = arr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- ActiveWindow.DisplayZeros = False
- End With
- ws.Close 1
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
评分
-
3
查看全部评分
-
|