|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
代码更新如下:- Sub ykcbf() '//2024.2.29
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Dim arr, brr(1 To 100000, 1 To 100), d
- Dim tm: tm = Timer
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set d = CreateObject("Scripting.Dictionary")
- Set sh = ThisWorkbook.Sheets("工单列表")
- yf = Format(ThisWorkbook.Sheets("汇总").[g1], "yyyymm") '//条件1:按年+月汇总
- nf = Val(ThisWorkbook.Sheets("汇总").[g2]) '//条件2:按全年汇总
- With sh
- c = .UsedRange.Columns.Count
- For j = 2 To c + 1
- n = n + 1
- s = .Cells(1, j)
- d(s) = n
- Next
- End With
- st2 = Val(Application.InputBox("请选择汇总方式:1、按年月汇总,2、按全年汇总", "输入数字", 1, , , , , 1))
- '//文件夹动态选择
- With Application.FileDialog(msoFileDialogFolderPicker)
- .Title = "请选择文件夹"
- .InitialFileName = ThisWorkbook.Path & ""
- If .Show = -1 Then
- p = .SelectedItems(1) & ""
- End If
- End With
-
- ' p = "D:\重要文件\Desktop\新建文件夹\故障汇报\故障清单" '//指定文件夹
- On Error Resume Next
- For Each f In fso.GetFolder(p).Files
- If f.Name Like "*.xls*" Then
- If InStr(f.Name, ThisWorkbook.Name) = 0 Then
- fn = fso.GetBaseName(f)
- Select Case st2
- Case Is = 1
- rq = Left(Replace(fn, "故障清单", ""), 6)
- 日期条件 = yf
- Case Is = 2
- rq = Val(Mid(fn, 5, 4))
- 日期条件 = nf
- End Select
- If rq = 日期条件 Then
- Set wb = Workbooks.Open(f, 0)
- With wb.Sheets(1)
- arr = .UsedRange
- wb.Close False
- End With
- For i = 2 To UBound(arr)
- If arr(i, 1) <> Empty Then
- m = m + 1
- For j = 1 To UBound(arr, 2)
- s = arr(1, j)
- If d.exists(s) Then
- brr(m, d(s)) = arr(i, j)
- End If
- Next
- End If
- Next
- End If
- End If
- End If
- Next f
- With sh
- .UsedRange.Offset(1).Clear
- With .[b2].Resize(m, n)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "共用时:" & Format(Timer - tm) & "秒!"
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|