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\"
Application.DisplayAlerts = False
Sheets("DATA").Delete
Application.DisplayAlerts = True
Worksheets.Add(before:=Sheets("CALCULATOR")).Name = "DATA"
Columns("C:C").NumberFormat = "m/d/yyyy"
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
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))"
Sheets("CAREER FLG").Range("C4").AutoFill Destination:=Sheets("CAREER FLG").Range("C4:O4"), Type:=xlFillDefault
Sheets("CAREER FLG").Range("C4:O4").AutoFill Destination:=Sheets("CAREER FLG").Range("C4:O23"), Type:=xlFillDefault
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub