Public Sub accrued_pto_20()
Dim Location As String, Month As String, Facility As String, Cycle As String, Kronos As String, Effective As String
Sheets("Sheet1").Name = "" & Facility & "_Accrued_PTO_Dollars"
Cells.Replace What:="RESET", Replacement:="1RESET", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Columns("I:o").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("Table1[[#Headers],[Column1]]").Select
ActiveCell.FormulaR1C1 = "Calculation"
Range("Table1[[#Headers],[Column2]]").Select
ActiveCell.FormulaR1C1 = "Subtotal"
Range("Table1[[#Headers],[Column3]]").Select
ActiveCell.FormulaR1C1 = "PTO Hours"
Range("Table1[[#Headers],[Column4]]").Select
ActiveCell.FormulaR1C1 = "PTO Dollars"
Range("Table1[[#Headers],[Column5]]").Select
ActiveCell.FormulaR1C1 = "Pay Rate"
Range("Table1[[#Headers],[Column6]]").Select
ActiveCell.FormulaR1C1 = "Job Code"
Range("Table1[[#Headers],[Column7]]").Select
ActiveCell.FormulaR1C1 = "Department"
Range("I2").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-5]<>R[-1]C[-5],RC[-1],IF(RC[-2]=""1RESET"",RC[-1],IF(RC[-2]=""TOTAL"",R[-1]C,RC[-1]+R[-1]C)))"
Range("J2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-6]<>R[1]C[-6],RC[-1],"""")"
Range("K2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]<>"""",ROUND(RC[-1],2),"""")"
Range("L2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]="""","""",ROUND(RC[-1]*RC[-7],2))"
Range("M2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]="""","""",RC[-8])"
Range("N2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]<>"""",RC[2]*1,"""")"
Range("O2").Select
'===============
'Code breaks here.
ActiveCell.FormulaR1C1 = "=IF(RC[-1]="""","""",IF(OR(RC[-1]=880,RC[-1]=885),""Marketing"", IF(OR(RC[-1]=700,RC[-1]=705,RC[-1]=710,RC[-1]=715),""Management"",IF(OR(RC[-1]=890,RC[-1]=891,RC[-1]=895,RC[-1]=893,RC[-1]=835,RC[-1]=892,RC[-1]=896),""Operations"",IF(OR(RC[-1]=740,RC[-1]=745,RC[-1]=748,RC[-1]=750,RC[-1]=753,RC[-1]=755,RC[-1]=760),""Comm/Dev"",IF(OR(RC[-1]=865,RC[-1]=870,RC[-1]=875,RC[-1]=862),""Clinical"",IF(OR(RC[-1]=765,RC[-1]=770,RC[-1]=773,RC[-1]=775,RC[-1]=778,RC[-1]=780,RC[-1]=782,RC[-1]=783,RC[-1]=810,RC[-1]=815),""Accounting"",IF(OR(RC[-1]=820,RC[-1]=823,RC[-1]=825,RC[-1]=830,RC[-1]=832),""Information Technology"",IF(OR(RC[-1]=768,RC[-1]=785,RC[-1]=790,RC[-1]=795,RC[-1]=800,RC[-1]=805,RC[-1]=806),""Billing"",IF(OR(RC[-1]=720,RC[-1]=725,RC[-1]=730,RC[-1]=735),""Human Resources"",IF(OR(RC[-1]=840,RC[-1]=845,RC[-1]=855,RC[-1]=860,RC[-1]=863),""Business OPs"", RC[-13])))))))))))"
Range("N3").Select
ActiveWorkbook.Worksheets("" & Facility & "_Accrued_PTO_Dollars").ListObjects( _
"Table1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("" & Facility & "_Accrued_PTO_Dollars").ListObjects( _
"Table1").Sort.SortFields.Add Key:=Range( _
"Table1[HOMELABORLEVELDSC2]"), SortOn:=xlSortOnValues _
, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("" & Facility & "_Accrued_PTO_Dollars").ListObjects( _
"Table1").Sort.SortFields.Add Key:=Range( _
"Table1[PERSONFULLNAME]"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("" & Facility & "_Accrued_PTO_Dollars").ListObjects( _
"Table1").Sort.SortFields.Add Key:=Range( _
"Table1[EFFECTIVEDATE]"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("" & Facility & "_Accrued_PTO_Dollars").ListObjects( _
"Table1").Sort.SortFields.Add Key:=Range( _
"Table1[ACCRUALTRANTYPENM]"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("" & Facility & "_Accrued_PTO_Dollars").ListObjects( _
"Table1").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Table1", Version:=xlPivotTableVersion12). _
CreatePivotTable TableDestination:="Sheet1!R3C1", TableName:="PivotTable2" _
, DefaultVersion:=xlPivotTableVersion12
Sheets("Sheet1").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Department")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("PERSONFULLNAME")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("PTO Hours"), "Count of PTO Hours", xlCount
ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("Pay Rate"), "Count of Pay Rate", xlCount
ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("PTO Dollars"), "Count of PTO Dollars", xlCount
ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("Job Code"), "Count of Job Code", xlCount
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Department")
.LayoutBlankLine = True
.LayoutCompactRow = False
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Count of PTO Hours")
.Caption = "Hours"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Count of Pay Rate")
.Caption = "Hourly Rate"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Count of PTO Dollars")
.Caption = "Dollars"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Count of Job Code")
.Caption = "JobCode"
.Function = xlSum
End With
Range("A5").Select
ActiveSheet.PivotTables("PivotTable2").PivotFields("Department").PivotItems("") _
.ShowDetail = False
Rows("5:5").Select
Selection.EntireRow.Hidden = True
ActiveSheet.PivotTables("PivotTable2").PivotSelect "Department[All;'Blank']", _
xlDataAndLabel + xlFirstRow, True
ActiveSheet.PivotTables("PivotTable2").TableStyle2 = "PivotStyleMedium2"
Rows("1:2").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A1").Select
ActiveCell.FormulaR1C1 = cboLocation
Range("A2").Select
ActiveCell.FormulaR1C1 = "Accrued PTO Dollars"
Range("A3").Select
ActiveCell.FormulaR1C1 = "Period Ending:"
Range("B3").Select
ActiveCell.FormulaR1C1 = Month
Range("B3").Select
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "Report"
Range("A6").Select
ActiveSheet.PivotTables("PivotTable2").CompactLayoutRowHeader = "Department"
Range("B6").Select
ActiveSheet.PivotTables("PivotTable2").PivotFields("PERSONFULLNAME").Caption = _
"Employee"
Range("C5").Select
ActiveSheet.PivotTables("PivotTable2").DataPivotField.Caption = " "
Range("C6").Select
With ActiveSheet.PageSetup
.PrintTitleRows = "$1:$4"
.PrintTitleColumns = ""
End With
ActiveSheet.PageSetup.PrintArea = ""
Range("C6:F6").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("A1").Select
Sheets("" & Facility & "_Accrued_PTO_Dollars").Select
ActiveWindow.SelectedSheets.Visible = False
' Sheets("Report").Print
ChDir "I:\Dept\Accounting\Payroll Reports - CO\Accrued PTO Dollars\FY11\"
ActiveWorkbook.SaveAs Filename:= _
"I:\Dept\Accounting\Payroll Reports - CO\Accrued PTO Dollars\FY11\" & Month & ".xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close
End Sub
Bookmarks