Long Code that needs to be debugged and possibly shortened.

Yuriy B

New Member
Joined
Feb 4, 2015
Messages
26
Hi,

I have a code that excel has generated from the "record macros" function. It doesn't always execute correctly.
1. Please review the macro and correct any issues that you may find.
2. Is there a way that a macro can include a specific printer and printer settings?
3. is there a way that a macro can be executed 5 days a week (Mon - Fri) at 8:10 AM without opening excel?


Macro:

Code:
Sub MacroPint3()
'
' MacroPint3 Macro
'

'
Sheets("Pnch, Asy, Oth, Mach SchedRsc").Select
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup").CurrentPage = _
"Assembly"
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc").ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc").CurrentPage = _
"(All)"
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=3, Copies:=1, Collate _
:=True, IgnorePrintAreas:=False
Sheets("Brk SchedPrimeRq").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("SchedGroup"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable1").PivotFields("SchedGroup").CurrentPage = _
"Brake"
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=3, Copies:=1, Collate _
:=True, IgnorePrintAreas:=False
Sheets("Asy,Lsr,HW,WD,SW,PC SchedRqList").Select
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup").CurrentPage = _
"Powder"
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=3, Copies:=1, Collate _
:=True, IgnorePrintAreas:=False
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup").CurrentPage = _
"SpotWeld"
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=3, Copies:=1, Collate _
:=True, IgnorePrintAreas:=False
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup").CurrentPage = _
"Weld"
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=3, Copies:=1, Collate _
:=True, IgnorePrintAreas:=False
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup").CurrentPage = _
"Hardware"
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=3, Copies:=1, Collate _
:=True, IgnorePrintAreas:=False
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup").CurrentPage = _
"LASER"
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=3, Copies:=1, Collate _
:=True, IgnorePrintAreas:=False
Sheets("Pnch, Asy, Oth, Mach SchedRsc").Select
Range("B1").Select
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup").CurrentPage = _
"Punch"
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc").ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc").CurrentPage = _
"TRUPUNCH2020"
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=3, Copies:=1, Collate _
:=True, IgnorePrintAreas:=False
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc").ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc").CurrentPage = _
"TRUPUNCH5000"
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=3, Copies:=1, Collate _
:=True, IgnorePrintAreas:=False
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc").ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc").CurrentPage = _
"TRUPUNCH50S12"
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=3, Copies:=1, Collate _
:=True, IgnorePrintAreas:=False
Sheets("Asy,Lsr,HW,WD,SW,PC SchedRqList").Select
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup").CurrentPage = _
"P2"
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=3, Copies:=1, Collate _
:=True, IgnorePrintAreas:=False
Sheets("Pnch, Asy, Oth, Mach SchedRsc").Select
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup").CurrentPage = _
"Grind"
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc").ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc").CurrentPage = "(All)"
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=3, Copies:=1, Collate _
:=True, IgnorePrintAreas:=False
Sheets("Asy,Lsr,HW,WD,SW,PC SchedRqList").Select
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup").CurrentPage = _
"Machining"
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=3, Copies:=1, Collate _
:=True, IgnorePrintAreas:=False
Sheets("Pnch, Asy, Oth, Mach SchedRsc").Select
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup").CurrentPage = _
"Other"
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc").ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc").CurrentPage = _
"PNCHPRES/TON"
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=3, Copies:=1, Collate _
:=True, IgnorePrintAreas:=False
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc").ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc").CurrentPage = _
"ASI CELL"
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=3, Copies:=1, Collate _
:=True, IgnorePrintAreas:=False
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc").ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc").CurrentPage = _
"WLDROBOTIC/LG"
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=3, Copies:=1, Collate _
:=True, IgnorePrintAreas:=False
Sheets("Pnch, Asy, Oth, Mach SchedRsc").Select
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup").CurrentPage = _
"Other"
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc").ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc").CurrentPage = _
"INSP/LASERQC"
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc").CurrentPage = "(All)"
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc")
.PivotItems("ASSEMBLY").Visible = False
.PivotItems("BLTSANDER/DRY").Visible = False
.PivotItems("BRK/HD/LG").Visible = False
.PivotItems("DEBURR/HAND").Visible = False
.PivotItems("FORM/P2").Visible = False
.PivotItems("GRNDING/VIBRAT").Visible = False
.PivotItems("HRDWRE/HAGER").Visible = False
.PivotItems("HRDWRE/STAMP").Visible = False
.PivotItems("LASER/2030").Visible = False
.PivotItems("POWDERCOATING").Visible = False
.PivotItems("SEND OUTSIDE").Visible = False
.PivotItems("SPTWLD/SNGLE").Visible = False
.PivotItems("TRUPUNCH2020").Visible = False
.PivotItems("TRUPUNCH5000").Visible = False
.PivotItems("TRUPUNCH50S12").Visible = False
.PivotItems("WELDING/MIG.").Visible = False
.PivotItems("WELDING/TIG").Visible = False
.PivotItems("WLD/ALUM/MIG.").Visible = False
.PivotItems("WLDROBOTIC/LG").Visible = False
.PivotItems("MACHINING").Visible = False
.PivotItems("PNCHPRES/TON").Visible = False
.PivotItems("ASI CELL").Visible = False
.PivotItems("BRK/COLLABROBOT").Visible = False
.PivotItems("MATERIALS GROUP").Visible = False
End With
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc"). _
EnableMultiplePageItems = True
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=3, Copies:=1, Collate _
:=True, IgnorePrintAreas:=False
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc").ClearAllFilters
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc")
.PivotItems("ASSEMBLY").Visible = True
.PivotItems("BLTSANDER/DRY").Visible = True
.PivotItems("BRK/HD/LG").Visible = True
.PivotItems("DEBURR/HAND").Visible = True
.PivotItems("FORM/P2").Visible = True
.PivotItems("GRNDING/VIBRAT").Visible = True
.PivotItems("HRDWRE/HAGER").Visible = True
.PivotItems("HRDWRE/STAMP").Visible = True
.PivotItems("LASER/2030").Visible = True
.PivotItems("POWDERCOATING").Visible = True
.PivotItems("SEND OUTSIDE").Visible = True
.PivotItems("SPTWLD/SNGLE").Visible = True
.PivotItems("TRUPUNCH2020").Visible = True
.PivotItems("TRUPUNCH5000").Visible = True
.PivotItems("TRUPUNCH50S12").Visible = True
.PivotItems("WELDING/MIG.").Visible = True
.PivotItems("WELDING/TIG").Visible = True
.PivotItems("WLD/ALUM/MIG.").Visible = True
.PivotItems("WLDROBOTIC/LG").Visible = True
.PivotItems("MACHINING").Visible = True
.PivotItems("PNCHPRES/TON").Visible = True
.PivotItems("ASI CELL").Visible = True
.PivotItems("BRK/COLLABROBOT").Visible = True
.PivotItems("MATERIALS GROUP").Visible = True
End With
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc"). _
EnableMultiplePageItems = False
ActiveSheet.PivotTables("PivotTable2").PivotFields("Rsc").CurrentPage = _
"TRUPUNCH5000"
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("SchedGroup").CurrentPage = _
"(All)"
End Sub
 
Last edited by a moderator:

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,215,375
Messages
6,124,592
Members
449,174
Latest member
chandan4057

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top