Sub combine()
Dim Arr, Brr, PH$, FN$, xB As Workbook, xS As Worksheet, i&, N&
ReDim Brr(1 To 60000, 0)
Application.ScreenUpdating = False
PH = ThisWorkbook.Path & "\TEST"
FN = Dir(PH & "\*.xls*")
Do While FN <> ""
Set xB = Workbooks.Open(PH & "\" & FN)
For Each xS In xB.Sheets
If xS.Name Like "Script_*" = False Then GoTo x01
With Range(xS.[a1], xS.Cells(Rows.Count, 1).End(3)(2))
On Error Resume Next
With .SpecialCells(xlCellTypeConstants, 16)
Application.Goto .Cells: MsgBox "修正錯誤": Exit Sub
'↑建議檢查/修正 資料檔錯誤值存檔關閉後再重新執行
'資料檔的錯誤格追究其原因是很重要的
'.ClearContents
'↑不建議直接清除跳過
End With
On Error GoTo 0
Arr = .Value
End With
For i = 1 To UBound(Arr) - 1
If Arr(i, 1) <> "" Then N = N + 1: Brr(N, 0) = Arr(i, 1)
Next i
x01: Next
xB.Close 0
FN = Dir
Loop
Set xB = Nothing: Set xS = Nothing
'=============================
ThisWorkbook.Activate
If N = 0 Then Exit Sub
Application.DisplayAlerts = False
On Error Resume Next: Sheets("Combine").Delete: On Error GoTo 0
With Worksheets.Add(After:=Sheets(Sheets.Count))
.[a1].Resize(N) = Brr
.Name = "Combine"
End With
Sheets(1).Select
End Sub作者: rcyw 時間: 2023-2-22 14:01