Sub EmpCenter_TimeWorked_Emp() '******************************************* 'Purpose: Used to format the output from EmpCenter: Timesheet Output Query 'Author: Brad Dennis 'Date: 11-21-2013 'Called by: 'Calls: 'Inputs: Timesheet Output Query CSV 'Output: EmpCenter_Time.xlsx on user's desktop 'Example: 'Revisions: 1-03-2014 Change lastrow variable to "long" ' 9-08-2014 Workforce changed the format of the CSV file, no longer need to delete columns A:K ' 9-10-2014 Call Strip_Header_Footer routine to delete bottom 4 rows and top 2 rows 'Notes: '******************************************* Cells.Select Cells.EntireColumn.AutoFit 'Range("A1:K1").Select 'Selection.EntireColumn.Delete Call Strip_Header_Footer 'To delete bottom 4 rows and top 2 rows Rows("1:1").Select Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove Range("A1").Select ActiveCell.FormulaR1C1 = "Employee" Range("B1").Select ActiveCell.FormulaR1C1 = "Assignment" Range("C1").Select ActiveCell.FormulaR1C1 = "Notes" Range("D1").Select ActiveCell.FormulaR1C1 = "Index" Range("E1").Select ActiveCell.FormulaR1C1 = "Activity" Range("F1:G1").Select ActiveWindow.SmallScroll Down:=-3 Selection.EntireColumn.Delete Range("G1").Select ActiveCell.FormulaR1C1 = "Slice Hrs" Range("H1").Select ActiveCell.FormulaR1C1 = "Slice $" Range("P2:AA2").Select Selection.EntireColumn.Delete Range("F1").Select ActiveCell.FormulaR1C1 = "Date" Columns("A:A").EntireColumn.AutoFit Columns("B:B").EntireColumn.AutoFit Range("I1:J1").Select Selection.EntireColumn.Delete Range("K1:K1").Select Selection.EntireColumn.Delete Range("M1:M1").Select Selection.EntireColumn.Delete Range("I1").Select ActiveCell.FormulaR1C1 = "Assn Hrs" Range("J1").Select ActiveCell.FormulaR1C1 = "Assn $" Range("K1").Select ActiveCell.FormulaR1C1 = "Empl Hrs" Range("L1").Select ActiveCell.FormulaR1C1 = "Empl $" Cells.Select Cells.EntireColumn.AutoFit Range("A1").Select 'Add Columns Columns("B:B").Select Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove Range("B1").Select ActiveCell.FormulaR1C1 = "ID" Range("B2").Select Columns("B:B").ColumnWidth = 8 Columns("D:F").Select Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove Range("D1").Select ActiveCell.FormulaR1C1 = "TS Org" Range("E1").Select ActiveCell.FormulaR1C1 = "Position" Range("F1").Select ActiveCell.FormulaR1C1 = "Suffix" Range("F2").Select 'Freeze Range("A1").Select Selection.Font.Bold = True With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = True End With Selection.Copy Rows("1:1").Select Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Application.CutCopyMode = False 'Extract Employee Name Columns("A:A").Select Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove Range("A2").Select Columns("A:A").ColumnWidth = 35 Range("A2").Select ActiveCell.FormulaR1C1 = "=MID(RC[1],11,LEN(RC[1])-22)" 'Now copy down the ranges Dim lastRow As Long 'Allows for 2 billion rows lastRow = f_LastRow Range("A2").Select Selection.Copy Range("A2:A" & lastRow).Select ActiveSheet.Paste Application.CutCopyMode = False Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("A1").Select Application.CutCopyMode = False ActiveCell.FormulaR1C1 = "Employee" Range("C2").Select Columns("C:C").ColumnWidth = 12 ActiveCell.FormulaR1C1 = "=MID(RC[-1],LEN(RC[-1])-9,9)" Range("C2").Select Range("C2").Select Selection.Copy Range("C2:C" & lastRow).Select ActiveSheet.Paste Application.CutCopyMode = False Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("B1").Select Application.CutCopyMode = False Selection.EntireColumn.Delete Columns("B:B").EntireColumn.AutoFit Columns("A:A").EntireColumn.AutoFit 'Parse Assignment Columns("D:D").Select Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove Range("D1").Select ActiveCell.FormulaR1C1 = "Assignment" Range("D2").Select ActiveCell.FormulaR1C1 = "=RIGHT(RC[-1],LEN(RC[-1])-12)" Range("D2").Select Range("D2").Select Selection.Copy Range("D2:D" & lastRow).Select ActiveSheet.Paste Application.CutCopyMode = False Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("C1").Select Application.CutCopyMode = False Selection.EntireColumn.Delete 'Freeze Row 1 Range("A2").Select ActiveWindow.FreezePanes = True Range("D2").Select ActiveCell.FormulaR1C1 = "=PERSONAL.XLSB!f_Parse_Assignment(RC[-1],2)" Range("E2").Select ActiveCell.FormulaR1C1 = "=PERSONAL.XLSB!f_Parse_Assignment(RC[-2],3)" Range("F2").Select ActiveCell.FormulaR1C1 = "=PERSONAL.XLSB!f_Parse_Assignment(RC[-3],4)" Range("F2").Select Columns("D:D").Select Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove ActiveWindow.SmallScroll ToRight:=2 Range("D1").Select ActiveCell.FormulaR1C1 = "Assignment" Range("D2").Select Columns("D:D").ColumnWidth = 45 ActiveWindow.ScrollColumn = 2 ActiveWindow.ScrollColumn = 1 Range("D2").Select ActiveCell.FormulaR1C1 = "=PERSONAL.XLSB!f_Parse_Assignment(RC[-1],1)" 'Copy formulas and convert to values Range("D2:G2").Select Selection.Copy Range("D2:G" & lastRow).Select ActiveSheet.Paste Application.CutCopyMode = False Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("A2").Select Application.CutCopyMode = False Cells.Select Cells.EntireColumn.AutoFit Range("C1").Select Selection.EntireColumn.Delete Range("A2").Select 'Find path of user's desktop Dim SavePath As String SavePath = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator 'Save File ActiveWorkbook.SaveAs Filename:=SavePath & "EmpCenter_Time.xlsx", _ FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False MsgBox "Finished" End Sub Sub EmpCenter_RedErrors() '******************************************* 'Purpose: Used to format the output from EmpCenter: Timesheet Exceptions within Date Range 'Author: Brad Dennis 'Date: 11-21-2013 'Called by: 'Calls: 'Inputs: Timesheet Exceptions Query CSV 'Output: EmpCenter_Errors.xlsx on user's desktop 'Example: 'Revisions: 1-03-2014 Change lastrow variable to "long" ' 9-10-2014 Workforce changed the format of the CSV file, no longer need to delete columns A:H ' 9-10-2014 Call Strip_Header_Footer routine to delete bottom 4 rows and top 2 rows 'Notes: '******************************************* Cells.Select Cells.EntireColumn.AutoFit 'Columns("A:H").Select 'Selection.EntireColumn.Delete Call Strip_Header_Footer 'To delete bottom 4 rows and top 2 rows Rows("1:1").Select Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove Range("G1:R1").Select Selection.EntireColumn.Delete Range("E3").Select Selection.EntireColumn.Delete Range("A1").Select ActiveCell.FormulaR1C1 = "Employee" Range("B1").Select ActiveCell.FormulaR1C1 = "ID" Range("C1").Select ActiveCell.FormulaR1C1 = "Assignment" Range("D1").Select ActiveCell.FormulaR1C1 = "Date" Range("E1").Select ActiveCell.FormulaR1C1 = "Message" 'Insert Columns Columns("D:G").Select Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove Range("D1").Select ActiveCell.FormulaR1C1 = "Assignment" Range("E1").Select Columns("D:D").ColumnWidth = 30 ActiveCell.FormulaR1C1 = "TS Org" Range("F1").Select Columns("E:E").ColumnWidth = 14 Range("F1").Select ActiveCell.FormulaR1C1 = "Posn" Range("G1").Select Columns("F:F").ColumnWidth = 10 Range("G1").Select ActiveCell.FormulaR1C1 = "Suffix" Columns("G:G").ColumnWidth = 10 'Freeze top row Rows("1:1").Select Selection.Font.Bold = True Range("A2").Select ActiveWindow.FreezePanes = True 'Insert formulas to parse Assignment Range("D2").Select ActiveCell.FormulaR1C1 = "=PERSONAL.XLSB!f_Parse_Assignment(RC[-1],1)" Range("E2").Select ActiveCell.FormulaR1C1 = "=PERSONAL.XLSB!f_Parse_Assignment(RC[-2],2)" Range("F2").Select ActiveCell.FormulaR1C1 = "=PERSONAL.XLSB!f_Parse_Assignment(RC[-3],3)" Range("G2").Select ActiveCell.FormulaR1C1 = "=PERSONAL.XLSB!f_Parse_Assignment(RC[-4],4)" 'Now copy down the formulas Dim lastRow As Long 'Allows for 2 billion rows lastRow = f_LastRow Range("D2:G2").Select Selection.Copy Range("D2:G" & lastRow).Select ActiveSheet.Paste Application.CutCopyMode = False Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False 'Final cleanup Range("A2").Select Application.CutCopyMode = False Cells.Select Cells.EntireColumn.AutoFit 'Find path of user's desktop Dim SavePath As String SavePath = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator 'Save before deleting last two columns ActiveWorkbook.SaveAs Filename:=SavePath & "EmpCenter_Errors.xlsx", _ FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False 'Delete the concatenated columns Range("C2").Select Selection.EntireColumn.Delete Range("A2").Select 'Save Again ActiveWorkbook.Save MsgBox "Finished" End Sub Public Function f_LastRow() As Long '******************************************* 'Purpose: Determines the last row of a spreadsheet 'Author: Brad Dennis 'Date: 11-13-2013 'Called by: 'Calls: 'Inputs: 'Output: 'Example: ?f_LastRow 'Revisions: 1-03-2014 Changed function to a datatype of long 'Notes: This is used to know how far down to fill a column with a formula '******************************************* Dim aRange As Range Set aRange = Range("A1").SpecialCells(xlCellTypeLastCell) f_LastRow = aRange.Row End Function Public Function f_Parse_Assignment(strAssignment As String, colAssignment As Integer) As String '******************************************* 'Purpose: Used to parse a concatenated assignment 'Author: Brad Dennis 'Date: 11-15-2013 'Called by: 'Calls: 'Inputs: Assignment String plus a value, 1, 2, 3 or 4 'Output: Returns a field from within the string - fields 1-4 'Example: ?f_Parse_Assignment("UHDS MPW Tomassito's-160659-C50113-00",3) ' ?f_Parse_Assignment("AD Maint Support-490000-C50277-00*2013-10-16",2) 'Revisions: 1-15-2014 Add coding for underscore character 'Notes: 1=Assignment Name; 2=TS Org; 3=Posn; 4=Suffix '******************************************* Dim blnAsterisk As Boolean Dim strAsterisk As String strAsterisk = Chr(42) Dim blnUnderscore As Boolean Dim strUnderscore As String strUnderscore = Chr(95) Dim intLen As Integer intLen = Len(strAssignment) 'See if the passed string contains an asterisk If InStr(strAssignment, strAsterisk) Then blnAsterisk = True Else blnAsterisk = False End If 'See if the passed string contains an underscore If InStr(strAssignment, strUnderscore) Then blnUnderscore = True Else blnUnderscore = False End If Select Case colAssignment Case 1 'Display Name If Not blnAsterisk Then f_Parse_Assignment = Left(strAssignment, (intLen - 17)) Else f_Parse_Assignment = Left(strAssignment, (intLen - 28)) End If Case 2 'TS org If Not blnAsterisk Then f_Parse_Assignment = Mid(strAssignment, (intLen - 15), 6) Else f_Parse_Assignment = Mid(strAssignment, (intLen - 26), 6) End If Case 3 'Position If Not blnAsterisk Then f_Parse_Assignment = Mid(strAssignment, (intLen - 8), 6) Else f_Parse_Assignment = Mid(strAssignment, (intLen - 19), 6) End If Case 4 'Suffix If Not blnAsterisk Then f_Parse_Assignment = Mid(strAssignment, (intLen - 1), 2) Else f_Parse_Assignment = Mid(strAssignment, (intLen - 12), 2) End If End Select End Function Sub EmpCenter_TimeWorked_Assn() '******************************************* 'Purpose: Used to format the output from EmpCenter: Timesheet Output Query 'Author: Brad Dennis 'Date: 12-02-2013 'Called by: 'Calls: 'Inputs: Timesheet Output Query CSV 'Output: EmpCenter_Time.xlsx on user's desktop 'Example: 'Revisions: 1-03-2014 Change lastrow variable to "long" ' 9-08-2014 Workforce changed the format of the CSV file, no longer need to delete columns A:K ' 9-10-2014 Call Strip_Header_Footer routine to delete bottom 4 rows and top 2 rows 'Notes: '******************************************* Cells.Select Cells.EntireColumn.AutoFit 'Range("A1:K1").Select 'Selection.EntireColumn.Delete Call Strip_Header_Footer 'To delete bottom 4 rows and top 2 rows Rows("1:1").Select Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove Range("A1").Select ActiveCell.FormulaR1C1 = "Employee" Range("B1").Select ActiveCell.FormulaR1C1 = "Assignment" Range("C1").Select ActiveCell.FormulaR1C1 = "Notes" Range("D1").Select ActiveCell.FormulaR1C1 = "Index" Range("E1").Select ActiveCell.FormulaR1C1 = "Activity" Range("F1:G1").Select ActiveWindow.SmallScroll Down:=-3 Selection.EntireColumn.Delete Range("G1").Select ActiveCell.FormulaR1C1 = "Slice Hrs" Range("H1").Select ActiveCell.FormulaR1C1 = "Slice $" Range("P2:AA2").Select Selection.EntireColumn.Delete Range("F1").Select ActiveCell.FormulaR1C1 = "Date" Columns("A:A").EntireColumn.AutoFit Columns("B:B").EntireColumn.AutoFit Range("I1:J1").Select Selection.EntireColumn.Delete Range("K1:K1").Select Selection.EntireColumn.Delete Range("M1:M1").Select Selection.EntireColumn.Delete Range("I1").Select ActiveCell.FormulaR1C1 = "Assn Hrs" Range("J1").Select ActiveCell.FormulaR1C1 = "Assn $" Range("K1").Select ActiveCell.FormulaR1C1 = "Empl Hrs" Range("L1").Select ActiveCell.FormulaR1C1 = "Empl $" Cells.Select Cells.EntireColumn.AutoFit Range("A1").Select 'Add Columns Columns("B:B").Select Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove Range("B1").Select ActiveCell.FormulaR1C1 = "ID" Range("B2").Select Columns("B:B").ColumnWidth = 8 Columns("D:F").Select Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove Range("D1").Select ActiveCell.FormulaR1C1 = "TS Org" Range("E1").Select ActiveCell.FormulaR1C1 = "Position" Range("F1").Select ActiveCell.FormulaR1C1 = "Suffix" Range("F2").Select 'Freeze Range("A1").Select Selection.Font.Bold = True With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = True End With Selection.Copy Rows("1:1").Select Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Application.CutCopyMode = False 'Search & Replace Cells.Replace What:="Employee: ", Replacement:="", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False Cells.Replace What:="Assignment: ", Replacement:="", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False Cells.Replace What:=" (", Replacement:=":", LookAt:=xlPart, SearchOrder:= _ xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False Cells.Replace What:=")", Replacement:="", LookAt:=xlPart, SearchOrder:= _ xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False 'Freeze Row 1 Range("A2").Select ActiveWindow.FreezePanes = True Range("B2").Select Columns("B:B").ColumnWidth = 10# ActiveCell.FormulaR1C1 = "=RIGHT(RC[-1],9)" Range("D2").Select ActiveCell.FormulaR1C1 = "=PERSONAL.XLSB!f_Parse_Assignment(RC[-1],2)" Range("E2").Select ActiveCell.FormulaR1C1 = "=PERSONAL.XLSB!f_Parse_Assignment(RC[-2],3)" Range("F2").Select ActiveCell.FormulaR1C1 = "=PERSONAL.XLSB!f_Parse_Assignment(RC[-3],4)" Range("F2").Select Columns("D:D").Select Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove ActiveWindow.SmallScroll ToRight:=2 Range("D1").Select ActiveCell.FormulaR1C1 = "Assignment" Range("D2").Select Columns("D:D").ColumnWidth = 42.14 ActiveWindow.ScrollColumn = 2 ActiveWindow.ScrollColumn = 1 Columns("B:B").Select Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove Range("B1").Select ActiveCell.FormulaR1C1 = "Employee" Range("B2").Select ActiveCell.FormulaR1C1 = "=LEFT(RC[-1],LEN(RC[-1])-10)" Range("E2").Select ActiveCell.FormulaR1C1 = "=PERSONAL.XLSB!f_Parse_Assignment(RC[-1],1)" Range("B2").Select Columns("B:B").ColumnWidth = 33.71 Range("B2").Select 'Now copy down the ranges Dim lastRow As Long 'Allows for 2 billion rows lastRow = f_LastRow Range("B2:C2").Select Selection.Copy Range("B2:C" & lastRow).Select ActiveSheet.Paste Application.CutCopyMode = False Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("E2:H2").Select Selection.Copy Range("E2:H" & lastRow).Select ActiveSheet.Paste Application.CutCopyMode = False Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("A2").Select Application.CutCopyMode = False Cells.Select Cells.EntireColumn.AutoFit 'Find path of user's desktop Dim SavePath As String SavePath = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator 'Save before deleting last two columns ActiveWorkbook.SaveAs Filename:=SavePath & "EmpCenter_Time.xlsx", _ FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False 'Delete the 2 concatenated columns Range("D2").Select Selection.EntireColumn.Delete Range("A2").Select Selection.EntireColumn.Delete 'Move Assignment column to column A Columns("C:C").Select Selection.Cut Columns("A:A").Select Selection.Insert Shift:=xlToRight 'Select entire range of data Range("A1").Select Range("A1:P" & lastRow).Select 'Set sort fields ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields. _ Clear ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields. _ Add Key:=Range("A2:A" & lastRow), SortOn:=xlSortOnValues, Order:=xlAscending, _ DataOption:=xlSortNormal ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields. _ Add Key:=Range("B2:B" & lastRow), SortOn:=xlSortOnValues, Order:=xlAscending, _ DataOption:=xlSortNormal ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields. _ Add Key:=Range("J2:J" & lastRow), SortOn:=xlSortOnValues, Order:=xlAscending, _ DataOption:=xlSortNormal With ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort .SetRange Range("A1:P" & lastRow) .Header = xlYes .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With Range("A2").Select 'Save Again ActiveWorkbook.Save MsgBox "Finished" End Sub Private Sub Strip_Header_Footer() '******************************************* 'Purpose: Used to Strip bottom 4 rows and top 2 rows from CSV file after WorkForce altered format 'Author: Brad Dennis 'Date: 09-10-2014 'Called by: 'Calls: 'Inputs: CSV from report 'Output: 'Example: 'Revisions: 'Notes: '******************************************* Dim lastRow As Long lastRow = f_LastRow 'Delete bottom 4 rows Range("A" & (lastRow - 3) & ":A" & lastRow).Select Selection.EntireRow.Delete 'Delete top 2 rows Range("A1:A2").Select Selection.EntireRow.Delete Range("A1").Select End Sub