Sub macro6()
UserForm1.Show
End Sub
Private Sub btnFilter_Click()
Dim startDate As String
Dim shift As String
'reads date from the userform
startDate = tbstartdate.Value 'tbStartDate is the name of the textbox for Starting Date
shift = tbshift 'tbshift is the name of the textbox for shift
'FILTERS
With Worksheets("sheet1")
.AutoFilterMode = False
.Range("a1:p1").AutoFilter
.Range("a1:p1").AutoFilter Field:=2, Criteria1:=shift
.Range("a1:p1").AutoFilter Field:=1, Criteria1:=(">=" & startDate), _
Operator:=xlAnd, Criteria2:=("<=" & startDate)
UserForm1.Hide
Range("A1:P" & Cells(Rows.Count, "A").End(xlUp).Row).Select
End With
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Sort Key1:=Range("E2"), Order1:=xlAscending, Key2:=Range("C2") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom
Selection.Subtotal GroupBy:=3, Function:=xlAverage, TotalList:=Array(6, 7, _
8, 9), Replace:=True, PageBreaks:=False, SummaryBelowData:=True
Range("a1").Select
Range("A1:P" & Cells(Rows.Count, "C").End(xlUp).Row).Select
With Selection.Font
.Size = 9
Selection.AutoFormat Format:=xlRangeAutoFormatSimple, Number:=True, Font _
:=True, Alignment:=True, Border:=True, Pattern:=True, Width:=True
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With
Range("A1:P1").Select
With Selection.Font
.Size = 8.5
End With
With ActiveSheet.PageSetup
.CenterHeader = "&D &T"
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.CenterHorizontally = True
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = True
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.PrintArea = ActiveSheet.UsedRange.Address
End With
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
ActiveWindow.Close
Application.DisplayAlerts = False
Savechanges = True
Application.DisplayAlerts = True
Range("a1").Select
Selection.AutoFilter
Selection.AutoFilter
End Sub
Private Sub btnFilter_Click()
Dim startDate As String
Dim shift As String
'reads date from the userform
startDate = tbstartdate.Value 'tbStartDate is the name of the textbox for Starting Date
shift = tbshift 'tbshift is the name of the textbox for shift
Application.DisplayAlerts = False
'FILTERS
With Worksheets("sheet1")
.AutoFilterMode = False
.Range("a1:p1").AutoFilter
.Range("a1:p1").AutoFilter Field:=2, Criteria1:=shift
.Range("a1:p1").AutoFilter Field:=1, Criteria1:=(">=" & startDate), _
Operator:=xlAnd, Criteria2:=("<=" & startDate)
UserForm1.Hide
Range("A1:P" & Cells(Rows.Count, "A").End(xlUp).Row).Copy
End With
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Sort Key1:=Range("E2"), Order1:=xlAscending, Key2:=Range("C2") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom
Selection.Subtotal GroupBy:=3, Function:=xlAverage, TotalList:=Array(6, 7, _
8, 9), Replace:=True, PageBreaks:=False, SummaryBelowData:=True
With Range("A1:P" & Cells(Rows.Count, "C").End(xlUp).Row)
Font.Size = 9
.AutoFormat Format:=xlRangeAutoFormatSimple, Number:=True, Font _
:=True, Alignment:=True, Border:=True, Pattern:=True, Width:=True
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With
With Range("A1:P1").Font
.Size = 8.5
End With
With ActiveSheet.PageSetup
.CenterHeader = "&D &T"
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.CenterHorizontally = True
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = True
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.PrintArea = ActiveSheet.UsedRange.Address
End With
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
ActiveWindow.Close Savechanges:=True
Range("A1").AutoFilter
Range("A1").AutoFilter
Application.DisplayAlerts = True
End Sub