|
Sub 按钮1_Click()
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = ThisWorkbook.Path & "\"
.Title = "请选择需汇总文件所在文件夹"
If .Show Then pth = .SelectedItems(1) Else Exit Sub '
End With
Set d = CreateObject("scripting.dictionary")
Set fso = CreateObject("scripting.filesystemobject")
Set sh = ActiveSheet
arr = sh.[a1].Resize(9999, sh.UsedRange.Columns.Count)
For i = 2 To UBound(arr, 2)
d(arr(2, i)) = i
Next i
r = 2
Application.ScreenUpdating = False
Application.DisplayAlerts = False
sh.UsedRange.Offset(2).ClearContents
For Each f In fso.getfolder(pth).Files
With Workbooks.Open(f)
brr = .Sheets(1).UsedRange
.Close False
End With
For j = 3 To UBound(brr) - 1
r = r + 1
arr(r, 1) = r - 2
For i = 2 To UBound(brr, 2)
If d.exists(brr(2, i)) Then
arr(r, d(brr(2, i))) = brr(j, i)
End If
Next i
Next
Next f
sh.[a1].Resize(r, UBound(arr, 2)) = arr
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
|
评分
-
1
查看全部评分
-
|