FROGGER24
Well-known Member
- Joined
- May 22, 2004
- Messages
- 704
- Office Version
- 2013
- 2010
- Platform
- Windows
I have a some code that we use in our office that works ok on my pc. When others in the office try to use the macro the year gets changed to 19 instead of 09. The only problem I have is that the code seems to slow down when it is trying to print the worksheet out. Can the code be shortened up/cleaned up. We are looking for gridlines with inside /outside lines, landscape and left/right margins of .25
Sub IC_Delays()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Workbooks.Add
Windows("Delays List.xls").Activate
Range("F15:N" & Cells(Rows.Count, "F").End(xlUp).Row).Copy
Windows("Book4").Activate
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Range("A1:I" & Cells(Rows.Count, "A").End(xlUp).Row).Select
Selection.Sort Key1:=Range("E1"), Order1:=xlDescending, Header:=xlYes
Columns("F:G").Insert Shift:=xlToRight
Range("F1") = "Delay Start"
Range("G1") = "Delay Stop"
Range("F2").FormulaR1C1 = "=RC[2]+RC[3]"
Range("G2").FormulaR1C1 = "=RC[3]+RC[4]"
Range("F2:G" & Cells(Rows.Count, "A").End(xlUp).Row).FillDown
Columns("F:G").NumberFormat = "m/d/yy h:mm;@"
Cells.EntireColumn.AutoFit
Range("L2").FormulaR1C1 = "=IF(RC[-10]&RC[-7]=R[-1]C[-10]&R[-1]C[-7],0,1)"
Range("L2:L" & Cells(Rows.Count, "G").End(xlUp).Row).FillDown
Cells.Copy
Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
lastrow = Cells(Rows.Count, "G").End(xlUp).Row
For i = lastrow - 1 To 2 Step -1
If Range("L" & i).Value = 0 Then Rows(i).EntireRow.Delete
Next i
Range("E1").AutoFilter Field:=5, Criteria1:=">=2.5"
Windows("Delays List.xls").Close
ActiveSheet.PageSetup.PrintArea = "$A$1:$G$" & Range("A1").End(xlDown).Row
Range("A1:G" & Range("A1").End(xlDown).Row).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
ActiveWindow.View = xlPageBreakPreview
ActiveSheet.VPageBreaks(1).DragOff Direction:=xlToRight, RegionIndex:=1
ActiveWindow.View = xlNormalView
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
ActiveSheet.PageSetup.PrintArea = "$A$1:$G$" & Range("A1").End(xlDown).Row
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(1)
.BottomMargin = Application.InchesToPoints(1)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = True
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.PrintErrors = xlPrintErrorsDisplayed
End With
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sub IC_Delays()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Workbooks.Add
Windows("Delays List.xls").Activate
Range("F15:N" & Cells(Rows.Count, "F").End(xlUp).Row).Copy
Windows("Book4").Activate
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Range("A1:I" & Cells(Rows.Count, "A").End(xlUp).Row).Select
Selection.Sort Key1:=Range("E1"), Order1:=xlDescending, Header:=xlYes
Columns("F:G").Insert Shift:=xlToRight
Range("F1") = "Delay Start"
Range("G1") = "Delay Stop"
Range("F2").FormulaR1C1 = "=RC[2]+RC[3]"
Range("G2").FormulaR1C1 = "=RC[3]+RC[4]"
Range("F2:G" & Cells(Rows.Count, "A").End(xlUp).Row).FillDown
Columns("F:G").NumberFormat = "m/d/yy h:mm;@"
Cells.EntireColumn.AutoFit
Range("L2").FormulaR1C1 = "=IF(RC[-10]&RC[-7]=R[-1]C[-10]&R[-1]C[-7],0,1)"
Range("L2:L" & Cells(Rows.Count, "G").End(xlUp).Row).FillDown
Cells.Copy
Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
lastrow = Cells(Rows.Count, "G").End(xlUp).Row
For i = lastrow - 1 To 2 Step -1
If Range("L" & i).Value = 0 Then Rows(i).EntireRow.Delete
Next i
Range("E1").AutoFilter Field:=5, Criteria1:=">=2.5"
Windows("Delays List.xls").Close
ActiveSheet.PageSetup.PrintArea = "$A$1:$G$" & Range("A1").End(xlDown).Row
Range("A1:G" & Range("A1").End(xlDown).Row).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
ActiveWindow.View = xlPageBreakPreview
ActiveSheet.VPageBreaks(1).DragOff Direction:=xlToRight, RegionIndex:=1
ActiveWindow.View = xlNormalView
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
ActiveSheet.PageSetup.PrintArea = "$A$1:$G$" & Range("A1").End(xlDown).Row
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(1)
.BottomMargin = Application.InchesToPoints(1)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = True
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.PrintErrors = xlPrintErrorsDisplayed
End With
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Last edited by a moderator: