Sub CopyRange()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim lastRow As Long
Dim wkbDest As Workbook
Dim wkbSource As Workbook
Set wkbDest = ThisWorkbook
'Const strPath As String = "D:\Aircrew_Flying_Hour\"
Sheets("DATA").UsedRange.ClearContents
Const strPath As String = "C:\Test2\"
ChDir strPath
strExtension = Dir(strPath & "*.xlsx")
Application.DisplayAlerts = False
Do While strExtension <> ""
Set wkbSource = Workbooks.Open(strPath & strExtension, UpdateLinks:=False)
If wkbSource.name <> ThisWorkbook.name Then
With wkbSource
'.Sheets("Summary of the Year").Unprotect Password:="2501"
.Sheets("Summary of the Year").Range("F76:U76").Copy wkbDest.Sheets("DATA").Cells(1, 2)
.Sheets("Summary of the Year").Range("G77:U796").Copy
wkbDest.Sheets("DATA").Cells(Rows.Count, "C").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
.Close savechanges:=False
End With
strExtension = Dir
End If
Loop
Application.DisplayAlerts = True
lastRow = wkbDest.Worksheets("DATA").Cells(Rows.Count, "D").End(xlUp).Row
wkbDest.Sheets("DATA").Range("B1:Q" & lastRow).AutoFilter Field:=3, Criteria1:="="
wkbDest.Sheets("DATA").Range("B2:Q" & lastRow).SpecialCells(xlCellTypeVisible).EntireRow.Delete
If wkbDest.Sheets("DATA").AutoFilterMode Then wkbDest.Sheets("DATA").AutoFilterMode = False
With wkbDest.Sheets("DATA").Range("B2")
.Value = "1"
.AutoFill Destination:=Range("B2").Resize(Range("D" & Rows.Count).End(xlUp).Row), Type:=xlFillSeries
End With
lastRow = wkbDest.Worksheets("DATA").Cells(Rows.Count, "D").End(xlUp).Row
wkbDest.Worksheets("DATA").Sort.SortFields.Clear
wkbDest.Worksheets("DATA").Sort.SortFields.Add Key:=Range("C2:C" & lastRow) _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With wkbDest.Worksheets("DATA").Sort
.SetRange Range("C1:C" & lastRow)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub