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
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
With wkbDest.Sheets("DATA").Cells(Rows.Count, "C").End(xlUp).Offset(1, 0)
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
End With
.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
wkbDest.Sheets("DATA").Range("B2").Resize(Range("D" & Rows.Count).End(xlUp).Row).Borders.LineStyle = xlContinuous
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
wkbDest.Sheets("DATA").Columns.AutoFit
With Sheets("CAREER FLG")
.Range("C4").FormulaArray = "=IF(SUMIF(DATA!$D$2:$D$4001,$B4,DATA!E$2:E$4001)=0,"""",SUMIF(DATA!$D$2:$D$4001,$B4,DATA!E$2:E$4001))"
.Range("C4").AutoFill Destination:=Sheets("CAREER FLG").Range("C4:O4"), Type:=xlFillDefault
.Range("C4:O4").AutoFill Destination:=Sheets("CAREER FLG").Range("C4:O23"), Type:=xlFillDefault
.Range("B4").FormulaArray = "=IFERROR(INDEX(DATA!$D$2:$D$4001,SMALL(IF((COUNTIF(B$3:B3,DATA!$D$2:$D$4001)=0)*(DATA!$D$2:$D$4001<>0),ROW(DATA!$D$2:$D$4001),""""),1)-ROW(DATA!$D$2)+1),"""")"
.Range("B4").AutoFill Destination:=.Range("B4:B23"), Type:=xlFillDefault
End With
With Sheets("CALCULATOR")
.Range("C90").FormulaArray = "=IFERROR(INDEX(DATA!C$2:C$4001,SMALL(IF(DATA!$C$2:$C$4001>=$R$9,IF(DATA!$C$2:$C$4001<=$R$11,ROW(DATA!$C$2:$C$4001)-ROW(DATA!$C$2)+1)),ROWS($R$9:$R$9))),"""")"
.Range("C90").AutoFill Destination:=.Range("C90:Q90"), Type:=xlFillDefault
.Range("C90:Q90").AutoFill Destination:=.Range("C90:Q4089"), Type:=xlFillDefault
End With
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub