|
多工作簿合并- Sub ykcbf() '//2024.7.30
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Dim arr, brr(1 To 10000, 1 To 30)
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set d = CreateObject("Scripting.Dictionary")
- Set sh = ThisWorkbook.Sheets("物资汇总表")
- p = ThisWorkbook.Path & "\申请单"
- b = [{1,3,4,5,12}]
- For Each f In fso.GetFolder(p).Files
- If LCase$(f.Name) Like "*.xls*" Then
- fn = fso.GetBaseName(f)
- Set wb = Workbooks.Open(f, 0)
- With wb.Sheets("物资需求计划报审表-设备配件")
- arr = .UsedRange
- End With
- wb.Close 0
- For i = 6 To UBound(arr)
- If Val(arr(i, 1)) Then
- s = arr(i, 3) & "|" & arr(i, 4) & "|" & arr(i, 5)
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- brr(m, 1) = m
- For x = 2 To UBound(b)
- brr(m, x) = arr(i, b(x))
- Next
- Else
- r = d(s)
- brr(r, 5) = brr(r, 5) + arr(i, 12)
- End If
- End If
- Next
- End If
- Next f
- With sh
- .UsedRange.Offset(5).ClearContents
- With .[a6].Resize(m, 5)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|