Public Sub TextToCol1()
Dim ws As Worksheet, lRow As Long
Set ws = ActiveWorkbook.Worksheets("LAVEXPORT")
ws.Range("B2:C3000").ClearContents
With ws
lRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("A1:A" & lRow).TextToColumns Semicolon:=True
.Range("A1:N3000").AutoFilter
.Range("A1:N3000").VerticalAlignment = xlCenter
.Range("A1:N3000").HorizontalAlignment = xlCenter
.Range("A1:N3000").Columns.AutoFit
End With
End Sub
Public Sub SortingColumnsInRange_v2()
Dim i As Long
Dim ShiftNames As Variant
Const FrmlaBases As String = "#=COUNT('^'!E2:E1000)|#=COUNTIF('^'!I2:I1000,""yes"")||#=COUNTIF('^'!L2:L1000,""Critical"")|#=COUNTIFS('^'!L2:L1000,""Critical"",'^'!I2:I1000,""Yes"")|"
ShiftNames = Split("AM PM RON")
Range("A:N").Sort key1:=Columns("E"), Order1:=xlAscending, Key2:=Columns("F"), Order2:=xlAscending, Header:=xlYes
Sheets.Add(After:=Sheets("LAVEXPORT")).Name = "Counts"
For i = 0 To UBound(ShiftNames)
Sheets.Add(Before:=Sheets("Counts")).Name = ShiftNames(i)
With Sheets("Counts")
.Cells(1, i + 2).Value = ShiftNames(i)
With .Cells(2, i + 2).Resize(6)
.Value = Application.Transpose(Split(Replace(FrmlaBases, "^", ShiftNames(i)), "|"))
.Replace What:="#", Replacement:="", LookAt:=xlPart
End With
End With
Next i
With Sheets("Counts")
.Range("A2:A7").Value = Application.Transpose(Array("Overall Flights Count", "Overall Flights Completed", "Overall Completion Rate (%)", "Critical Flights Count", "Critical Flights Completed", "Critical Completion Rate (%)"))
.UsedRange.EntireColumn.ColumnWidth = 15
.Rows(1).HorizontalAlignment = xlCenter
With .Range("B4:D4,B7:D7")
.NumberFormat = "0.0%"
.FormulaR1C1 = "=IF(R[-2]C=0,"""",R[-1]C/R[-2]C)"
End With
End With
End Sub
Sub Test()
Dim rCrit As Range
With Sheets("LAVEXPORT").Range("A1").CurrentRegion
Set rCrit = .Offset(, .Columns.Count + 1).Resize(2, 1)
rCrit.Cells(2).Formula = "=LET(StartT,TIME(6,30,0),EndT,TIME(15,00,0),OR(AND(F2>=StartT,G2<=EndT,F2>=StartT,F2<=EndT),AND(G2="""",F2>=StartT,F2<=EndT),AND(F2<=StartT,G2>=StartT,G2<=EndT),AND(F2>EndT,G2>=StartT,G2<=EndT)))"
.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=rCrit, CopyToRange:=Sheets("AM").Range("A1"), Unique:=False
rCrit.ClearContents
End With
With Sheets("LAVEXPORT").Range("A1").CurrentRegion
Set rCrit = .Offset(, .Columns.Count + 1).Resize(2, 1)
rCrit.Cells(2).Formula = "=LET(StartT,TIME(15,01,0),EndT,TIME(23,00,0),OR(AND(G2>=StartT,G2<=EndT,F2>=StartT,F2<=EndT),AND(G2="""",F2>=StartT,F2<=EndT),AND(F2<=StartT,G2>=StartT,G2<=EndT),AND(F2>EndT,G2>=StartT,G2<=EndT)))"
'rCrit.Cells(2).Formula = "=LET(StartT,TIME(15,01,0),EndT,TIME(23,00,0),OR(AND(G2>=StartT,G2<=EndT,F2>=StartT,F2<=EndT),AND(G2="""",F2>=StartT,F2<=EndT),AND(F2>EndT,G2>=StartT,G2<=EndT)))"
.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=rCrit, CopyToRange:=Sheets("PM").Range("A1"), Unique:=False
rCrit.ClearContents
End With
With Sheets("LAVEXPORT").Range("A1").CurrentRegion
Set rCrit = .Offset(, .Columns.Count + 1).Resize(2, 1)
rCrit.Cells(2).Formula = "=LET(StartT,TIME(23,01,0),EndT,TIME(23,59,0),StartT2,TIME(00,00,0),EndT2,TIME(06,29,0),OR(AND(F2<=StartT, G2>=StartT, G2<=EndT, G2<>""""), AND(F2>=StartT, F2<=EndT, G2>=StartT, G2<=EndT, G2<>""""),AND(F2>=StartT, F2<=EndT, G2=""""),AND(F2>=StartT2, F2<=EndT2, G2=""""),AND(F2>=EndT2, G2>=StartT2, G2<=EndT2,G2<>""""), AND(F2>=StartT2, F2<=EndT2, G2>=StartT2, G2<=EndT2, G2<>""""), AND(F2>=EndT2, G2>=StartT2, G2<=EndT2, G2<>"""")))"
.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=rCrit, CopyToRange:=Sheets("RON").Range("A1"), Unique:=False
rCrit.ClearContents
End With
End Sub