+ Reply to Thread
Results 1 to 30 of 30

Loop Macro Excluding 1 specific sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    07-11-2012
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    48

    Loop Macro Excluding 1 specific sheet

    I need help with a macro? I need a loop macro performning print setup on all sheets excluding 1 specific sheet. Can I get help please?

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Loop Macro Excluding 1 specific sheet

    Do you have a sample file that you can upload?

    Also specify which is the print range.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Loop Macro Excluding 1 specific sheet

    Hi Noorie,

    Welcome to the forum. The best way would be to record a macro with all the settings you want. Then that code can be modified to use variables and the loop. With the exception. It would be great if you could post a copy of the workbook as well.

    Thanks

  4. #4
    Registered User
    Join Date
    07-11-2012
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: Loop Macro Excluding 1 specific sheet

    I can record a macro to to the print range... that part i think i can work with. I'm having problem with excluding 1 sheet from the loop. The file is pretty large. Basically, its 40 tabs (40 PLs) all print on one page each except for 1PL that prints on 2 pages. So I have to accomodate that in the macro somehow.

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Loop Macro Excluding 1 specific sheet

    You record the macro with all the settings you require. Post that code here and we can help you with the loops.

  6. #6
    Registered User
    Join Date
    07-11-2012
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: Loop Macro Excluding 1 specific sheet

    This is a loop macro I have so far that goes through all pages. I need 1 Sheet excluded from this loop called "S-5000 Facilities"

    Sub PAGESETUP1()
    '
    ' PAGESETUP1 Macro
    For i = Worksheets.Count To 3 Step -1
            Set ws = Worksheets(i)
            ws.Select
        Range("G:X").Select
        With ActiveSheet.PageSetup
            .PrintTitleRows = ""
            .PrintTitleColumns = "$G:$G"
        End With
        ActiveSheet.PageSetup.PrintArea = "$G:$X"
        With ActiveSheet.PageSetup
            .LeftHeader = ""
            .CenterHeader = ""
            .RightHeader = ""
            .LeftFooter = "&D - &T"
            .CenterFooter = "&Z&F"
            .RightFooter = "Page &P"
            .LeftMargin = Application.InchesToPoints(0.25)
            .RightMargin = Application.InchesToPoints(0.25)
            .TopMargin = Application.InchesToPoints(0.5)
            .BottomMargin = Application.InchesToPoints(0.5)
            .HeaderMargin = Application.InchesToPoints(0.5)
            .FooterMargin = Application.InchesToPoints(0.25)
            .PrintHeadings = False
            .PrintGridlines = False
            .PrintComments = xlPrintNoComments
            .PrintQuality = 600
            .CenterHorizontally = True
            .CenterVertically = False
            .Orientation = xlLandscape
            .Draft = False
            .PaperSize = xlPaperLetter
            .FirstPageNumber = xlAutomatic
            .Order = xlDownThenOver
            .BlackAndWhite = False
            .Zoom = False
            .FitToPagesWide = 1
            .FitToPagesTall = 1
            .PrintErrors = xlPrintErrorsDisplayed
            .OddAndEvenPagesHeaderFooter = False
            .DifferentFirstPageHeaderFooter = False
            .ScaleWithDocHeaderFooter = True
            .AlignMarginsHeaderFooter = False
            .EvenPage.LeftHeader.Text = ""
            .EvenPage.CenterHeader.Text = ""
            .EvenPage.RightHeader.Text = ""
            .EvenPage.LeftFooter.Text = ""
            .EvenPage.CenterFooter.Text = ""
            .EvenPage.RightFooter.Text = ""
            .FirstPage.LeftHeader.Text = ""
            .FirstPage.CenterHeader.Text = ""
            .FirstPage.RightHeader.Text = ""
            .FirstPage.LeftFooter.Text = ""
            .FirstPage.CenterFooter.Text = ""
            .FirstPage.RightFooter.Text = ""
            End With
            DoEvents
        Next
        
    End Sub
    Last edited by arlu1201; 07-11-2012 at 02:43 PM. Reason: Use code tags in future.

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Loop Macro Excluding 1 specific sheet

    Hi norrie007
    You can try this
    'Option Explicit
    
    Sub PAGESETUP1()
    '
    ' PAGESETUP1 Macro
        For i = Worksheets.Count To 3 Step -1
            Set ws = Worksheets(i)
            If Not ws.Name = "S-5000 Facilities" Then '<------ Insert Your Worksheet Name Here
                ws.Select
                Range("G:X").Select
                With ActiveSheet.PageSetup
                    .PrintTitleRows = ""
                    .PrintTitleColumns = "$G:$G"
                End With
                ActiveSheet.PageSetup.PrintArea = "$G:$X"
                With ActiveSheet.PageSetup
                    .LeftHeader = ""
                    .CenterHeader = ""
                    .RightHeader = ""
                    .LeftFooter = "&D - &T"
                    .CenterFooter = "&Z&F"
                    .RightFooter = "Page &P"
                    .LeftMargin = Application.InchesToPoints(0.25)
                    .RightMargin = Application.InchesToPoints(0.25)
                    .TopMargin = Application.InchesToPoints(0.5)
                    .BottomMargin = Application.InchesToPoints(0.5)
                    .HeaderMargin = Application.InchesToPoints(0.5)
                    .FooterMargin = Application.InchesToPoints(0.25)
                    .PrintHeadings = False
                    .PrintGridlines = False
                    .PrintComments = xlPrintNoComments
                    .PrintQuality = 600
                    .CenterHorizontally = True
                    .CenterVertically = False
                    .Orientation = xlLandscape
                    .Draft = False
                    .PaperSize = xlPaperLetter
                    .FirstPageNumber = xlAutomatic
                    .Order = xlDownThenOver
                    .BlackAndWhite = False
                    .Zoom = False
                    .FitToPagesWide = 1
                    .FitToPagesTall = 1
                    .PrintErrors = xlPrintErrorsDisplayed
                    .OddAndEvenPagesHeaderFooter = False
                    .DifferentFirstPageHeaderFooter = False
                    .ScaleWithDocHeaderFooter = True
                    .AlignMarginsHeaderFooter = False
                    .EvenPage.LeftHeader.Text = ""
                    .EvenPage.CenterHeader.Text = ""
                    .EvenPage.RightHeader.Text = ""
                    .EvenPage.LeftFooter.Text = ""
                    .EvenPage.CenterFooter.Text = ""
                    .EvenPage.RightFooter.Text = ""
                    .FirstPage.LeftHeader.Text = ""
                    .FirstPage.CenterHeader.Text = ""
                    .FirstPage.RightHeader.Text = ""
                    .FirstPage.LeftFooter.Text = ""
                    .FirstPage.CenterFooter.Text = ""
                    .FirstPage.RightFooter.Text = ""
                End With
                DoEvents
            End If '<----don't forget this line of code
        Next
    
    End Sub
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  8. #8
    Registered User
    Join Date
    07-11-2012
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: Loop Macro Excluding 1 specific sheet

    Hi John, I tried this code and the loop is still taking tab: S-5000 Facilities and applying the page setup. I need to skip this tab. What should I do?

  9. #9
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Loop Macro Excluding 1 specific sheet

    Hi noorie,

    Try this and let me know

    Sub PAGESETUP1()
    '
    ' PAGESETUP1 Macro
    Dim i As Long
    Dim ws As Worksheet
    
    For i = Worksheets.Count To 3 Step -1
        If Not Worksheets(i).Name = "S-5000 Facilities" Then
        
            Set ws = Worksheets(i)
            
            With ws.PageSetup
                .PrintTitleColumns = "$G:$G"
                .PrintArea = "$G:$X"
                .LeftFooter = "&D - &T"
                .CenterFooter = "&Z&F"
                .RightFooter = "Page &P"
                .LeftMargin = Application.InchesToPoints(0.25)
                .RightMargin = Application.InchesToPoints(0.25)
                .TopMargin = Application.InchesToPoints(0.5)
                .BottomMargin = Application.InchesToPoints(0.5)
                .HeaderMargin = Application.InchesToPoints(0.5)
                .FooterMargin = Application.InchesToPoints(0.25)
                .PrintComments = xlPrintNoComments
                .PrintQuality = 600
                .CenterHorizontally = True
                .Orientation = xlLandscape
                .PaperSize = xlPaperLetter
                .FirstPageNumber = xlAutomatic
                .Order = xlDownThenOver
                .BlackAndWhite = False
                .Zoom = False
                .FitToPagesWide = 1
                .FitToPagesTall = 1
                .PrintErrors = xlPrintErrorsDisplayed
                .ScaleWithDocHeaderFooter = True
            End With
            
            DoEvents
        End If
        
    Next
    
    End Sub

  10. #10
    Registered User
    Join Date
    07-11-2012
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: Loop Macro Excluding 1 specific sheet

    This code didnt work. Meaning the tab I didnt want to apply the page setup on was not skipped. :/

    Quote Originally Posted by fredlo2010 View Post
    Hi noorie,

    Try this and let me know

    Sub PAGESETUP1()
    '
    ' PAGESETUP1 Macro
    Dim i As Long
    Dim ws As Worksheet
    
    For i = Worksheets.Count To 3 Step -1
        If Not Worksheets(i).Name = "S-5000 Facilities" Then
        
            Set ws = Worksheets(i)
            
            With ws.PageSetup
                .PrintTitleColumns = "$G:$G"
                .PrintArea = "$G:$X"
                .LeftFooter = "&D - &T"
                .CenterFooter = "&Z&F"
                .RightFooter = "Page &P"
                .LeftMargin = Application.InchesToPoints(0.25)
                .RightMargin = Application.InchesToPoints(0.25)
                .TopMargin = Application.InchesToPoints(0.5)
                .BottomMargin = Application.InchesToPoints(0.5)
                .HeaderMargin = Application.InchesToPoints(0.5)
                .FooterMargin = Application.InchesToPoints(0.25)
                .PrintComments = xlPrintNoComments
                .PrintQuality = 600
                .CenterHorizontally = True
                .Orientation = xlLandscape
                .PaperSize = xlPaperLetter
                .FirstPageNumber = xlAutomatic
                .Order = xlDownThenOver
                .BlackAndWhite = False
                .Zoom = False
                .FitToPagesWide = 1
                .FitToPagesTall = 1
                .PrintErrors = xlPrintErrorsDisplayed
                .ScaleWithDocHeaderFooter = True
            End With
            
            DoEvents
        End If
        
    Next
    
    End Sub

  11. #11
    Registered User
    Join Date
    07-11-2012
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: Loop Macro Excluding 1 specific sheet

    Sorry Guys it actually worked. Thanks so much for your help. Both codes worked! I just had an extra - in the tab name. I have 1 last thing i need help with, is that can I possibly add page setup for Facilities in the same macro? So basically do the following for facilities tab and the rest is the loop above. Here is what I recorded for Facilities:
    Columns("G:X").Select
        Range("G12").Activate
        ActiveSheet.PageSetup.PrintArea = "$G:$X"
        ActiveWindow.View = xlPageBreakPreview
        ActiveWindow.SmallScroll Down:=45
        With ActiveSheet.PageSetup
            .PrintTitleRows = ""
            .PrintTitleColumns = "$G:$G"
        End With
        ActiveSheet.PageSetup.PrintArea = "$G:$X"
        With ActiveSheet.PageSetup
            .LeftHeader = ""
            .CenterHeader = ""
            .RightHeader = ""
            .LeftFooter = "&D - &T"
            .CenterFooter = "&Z&F"
            .RightFooter = "Page &P"
            .LeftMargin = Application.InchesToPoints(0.25)
            .RightMargin = Application.InchesToPoints(0.25)
            .TopMargin = Application.InchesToPoints(0.5)
            .BottomMargin = Application.InchesToPoints(0.5)
            .HeaderMargin = Application.InchesToPoints(0.5)
            .FooterMargin = Application.InchesToPoints(0.25)
            .PrintHeadings = False
            .PrintGridlines = False
            .PrintComments = xlPrintNoComments
            .PrintQuality = 600
            .CenterHorizontally = True
            .CenterVertically = False
            .Orientation = xlLandscape
            .Draft = False
            .PaperSize = xlPaperLetter
            .FirstPageNumber = xlAutomatic
            .Order = xlDownThenOver
            .BlackAndWhite = False
            .Zoom = False
            .FitToPagesWide = 1
            .FitToPagesTall = 2
            .PrintErrors = xlPrintErrorsDisplayed
            .OddAndEvenPagesHeaderFooter = False
            .DifferentFirstPageHeaderFooter = False
            .ScaleWithDocHeaderFooter = True
            .AlignMarginsHeaderFooter = False
            .EvenPage.LeftHeader.Text = ""
            .EvenPage.CenterHeader.Text = ""
            .EvenPage.RightHeader.Text = ""
            .EvenPage.LeftFooter.Text = ""
            .EvenPage.CenterFooter.Text = ""
            .EvenPage.RightFooter.Text = ""
            .FirstPage.LeftHeader.Text = ""
            .FirstPage.CenterHeader.Text = ""
            .FirstPage.RightHeader.Text = ""
            .FirstPage.LeftFooter.Text = ""
            .FirstPage.CenterFooter.Text = ""
            .FirstPage.RightFooter.Text = ""
        End With
        ActiveSheet.ResetAllPageBreaks
    '    Set ActiveSheet.HPageBreaks(2).Location = Range("G72")
        ActiveWindow.SmallScroll Down:=-66
        With ActiveSheet.PageSetup
            .PrintTitleRows = "$12:$21"
            .PrintTitleColumns = "$G:$G"
        End With
        ActiveSheet.PageSetup.PrintArea = "$G:$X"
        With ActiveSheet.PageSetup
            .LeftHeader = ""
            .CenterHeader = ""
            .RightHeader = ""
            .LeftFooter = "&D - &T"
            .CenterFooter = "&Z&F"
            .RightFooter = "Page &P"
            .LeftMargin = Application.InchesToPoints(0.25)
            .RightMargin = Application.InchesToPoints(0.25)
            .TopMargin = Application.InchesToPoints(0.5)
            .BottomMargin = Application.InchesToPoints(0.5)
            .HeaderMargin = Application.InchesToPoints(0.5)
            .FooterMargin = Application.InchesToPoints(0.25)
            .PrintHeadings = False
            .PrintGridlines = False
            .PrintComments = xlPrintNoComments
            .PrintQuality = 600
            .CenterHorizontally = True
            .CenterVertically = False
            .Orientation = xlLandscape
            .Draft = False
            .PaperSize = xlPaperLetter
            .FirstPageNumber = xlAutomatic
            .Order = xlDownThenOver
            .BlackAndWhite = False
            .Zoom = 57
            .PrintErrors = xlPrintErrorsDisplayed
            .OddAndEvenPagesHeaderFooter = False
            .DifferentFirstPageHeaderFooter = False
            .ScaleWithDocHeaderFooter = True
            .AlignMarginsHeaderFooter = False
            .EvenPage.LeftHeader.Text = ""
            .EvenPage.CenterHeader.Text = ""
            .EvenPage.RightHeader.Text = ""
            .EvenPage.LeftFooter.Text = ""
            .EvenPage.CenterFooter.Text = ""
            .EvenPage.RightFooter.Text = ""
            .FirstPage.LeftHeader.Text = ""
            .FirstPage.CenterHeader.Text = ""
            .FirstPage.RightHeader.Text = ""
            .FirstPage.LeftFooter.Text = ""
            .FirstPage.CenterFooter.Text = ""
            .FirstPage.RightFooter.Text = ""
        End With
        ActiveWindow.View = xlNormalView
    Last edited by arlu1201; 07-12-2012 at 09:42 AM. Reason: Use code tags in future.

  12. #12
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Loop Macro Excluding 1 specific sheet

    Hi Noorie
    Since you didn't post the complete code you may need to play with this
    'Option Explicit
    
    Sub PAGESETUP1()
    '
    ' PAGESETUP1 Macro
        For i = Worksheets.Count To 3 Step -1
            Set ws = Worksheets(i)
            If Not ws.Name = "S-5000 Facilities" Then    '<------ Insert Your Worksheet Name Here
                ws.Select
                Range("G:X").Select
                With ActiveSheet.PageSetup
                    .PrintTitleRows = ""
                    .PrintTitleColumns = "$G:$G"
                End With
                ActiveSheet.PageSetup.PrintArea = "$G:$X"
                With ActiveSheet.PageSetup
                    .LeftHeader = ""
                    .CenterHeader = ""
                    .RightHeader = ""
                    .LeftFooter = "&D - &T"
                    .CenterFooter = "&Z&F"
                    .RightFooter = "Page &P"
                    .LeftMargin = Application.InchesToPoints(0.25)
                    .RightMargin = Application.InchesToPoints(0.25)
                    .TopMargin = Application.InchesToPoints(0.5)
                    .BottomMargin = Application.InchesToPoints(0.5)
                    .HeaderMargin = Application.InchesToPoints(0.5)
                    .FooterMargin = Application.InchesToPoints(0.25)
                    .PrintHeadings = False
                    .PrintGridlines = False
                    .PrintComments = xlPrintNoComments
                    .PrintQuality = 600
                    .CenterHorizontally = True
                    .CenterVertically = False
                    .Orientation = xlLandscape
                    .Draft = False
                    .PaperSize = xlPaperLetter
                    .FirstPageNumber = xlAutomatic
                    .Order = xlDownThenOver
                    .BlackAndWhite = False
                    .Zoom = False
                    .FitToPagesWide = 1
                    .FitToPagesTall = 1
                    .PrintErrors = xlPrintErrorsDisplayed
                    .OddAndEvenPagesHeaderFooter = False
                    .DifferentFirstPageHeaderFooter = False
                    .ScaleWithDocHeaderFooter = True
                    .AlignMarginsHeaderFooter = False
                    .EvenPage.LeftHeader.Text = ""
                    .EvenPage.CenterHeader.Text = ""
                    .EvenPage.RightHeader.Text = ""
                    .EvenPage.LeftFooter.Text = ""
                    .EvenPage.CenterFooter.Text = ""
                    .EvenPage.RightFooter.Text = ""
                    .FirstPage.LeftHeader.Text = ""
                    .FirstPage.CenterHeader.Text = ""
                    .FirstPage.RightHeader.Text = ""
                    .FirstPage.LeftFooter.Text = ""
                    .FirstPage.CenterFooter.Text = ""
                    .FirstPage.RightFooter.Text = ""
                End With
                DoEvents
            End If    '<----don't forget this line of code
        Next
        Call PAGESETUP2 '<------- this line added
    End Sub
    
    
    Sub PAGESETUP2()
        Sheets("S-5000 Facilities").Activate
        Columns("G:X").Select
        Range("G12").Activate
        ActiveSheet.PageSetup.PrintArea = "$G:$X"
        ActiveWindow.View = xlPageBreakPreview
        ActiveWindow.SmallScroll Down:=45
        With ActiveSheet.PageSetup
            .PrintTitleRows = ""
            .PrintTitleColumns = "$G:$G"
        End With
        ActiveSheet.PageSetup.PrintArea = "$G:$X"
        With ActiveSheet.PageSetup
            .LeftHeader = ""
            .CenterHeader = ""
            .RightHeader = ""
            .LeftFooter = "&D - &T"
            .CenterFooter = "&Z&F"
            .RightFooter = "Page &P"
            .LeftMargin = Application.InchesToPoints(0.25)
            .RightMargin = Application.InchesToPoints(0.25)
            .TopMargin = Application.InchesToPoints(0.5)
            .BottomMargin = Application.InchesToPoints(0.5)
            .HeaderMargin = Application.InchesToPoints(0.5)
            .FooterMargin = Application.InchesToPoints(0.25)
            .PrintHeadings = False
            .PrintGridlines = False
            .PrintComments = xlPrintNoComments
            .PrintQuality = 600
            .CenterHorizontally = True
            .CenterVertically = False
            .Orientation = xlLandscape
            .Draft = False
            .PaperSize = xlPaperLetter
            .FirstPageNumber = xlAutomatic
            .Order = xlDownThenOver
            .BlackAndWhite = False
            .Zoom = False
            .FitToPagesWide = 1
            .FitToPagesTall = 2
            .PrintErrors = xlPrintErrorsDisplayed
            .OddAndEvenPagesHeaderFooter = False
            .DifferentFirstPageHeaderFooter = False
            .ScaleWithDocHeaderFooter = True
            .AlignMarginsHeaderFooter = False
            .EvenPage.LeftHeader.Text = ""
            .EvenPage.CenterHeader.Text = ""
            .EvenPage.RightHeader.Text = ""
            .EvenPage.LeftFooter.Text = ""
            .EvenPage.CenterFooter.Text = ""
            .EvenPage.RightFooter.Text = ""
            .FirstPage.LeftHeader.Text = ""
            .FirstPage.CenterHeader.Text = ""
            .FirstPage.RightHeader.Text = ""
            .FirstPage.LeftFooter.Text = ""
            .FirstPage.CenterFooter.Text = ""
            .FirstPage.RightFooter.Text = ""
        End With
        ActiveSheet.ResetAllPageBreaks
        '    Set ActiveSheet.HPageBreaks(2).Location = Range("G72")
        ActiveWindow.SmallScroll Down:=-66
        With ActiveSheet.PageSetup
            .PrintTitleRows = "$12:$21"
            .PrintTitleColumns = "$G:$G"
        End With
        ActiveSheet.PageSetup.PrintArea = "$G:$X"
        With ActiveSheet.PageSetup
            .LeftHeader = ""
            .CenterHeader = ""
            .RightHeader = ""
            .LeftFooter = "&D - &T"
            .CenterFooter = "&Z&F"
            .RightFooter = "Page &P"
            .LeftMargin = Application.InchesToPoints(0.25)
            .RightMargin = Application.InchesToPoints(0.25)
            .TopMargin = Application.InchesToPoints(0.5)
            .BottomMargin = Application.InchesToPoints(0.5)
            .HeaderMargin = Application.InchesToPoints(0.5)
            .FooterMargin = Application.InchesToPoints(0.25)
            .PrintHeadings = False
            .PrintGridlines = False
            .PrintComments = xlPrintNoComments
            .PrintQuality = 600
            .CenterHorizontally = True
            .CenterVertically = False
            .Orientation = xlLandscape
            .Draft = False
            .PaperSize = xlPaperLetter
            .FirstPageNumber = xlAutomatic
            .Order = xlDownThenOver
            .BlackAndWhite = False
            .Zoom = 57
            .PrintErrors = xlPrintErrorsDisplayed
            .OddAndEvenPagesHeaderFooter = False
            .DifferentFirstPageHeaderFooter = False
            .ScaleWithDocHeaderFooter = True
            .AlignMarginsHeaderFooter = False
            .EvenPage.LeftHeader.Text = ""
            .EvenPage.CenterHeader.Text = ""
            .EvenPage.RightHeader.Text = ""
            .EvenPage.LeftFooter.Text = ""
            .EvenPage.CenterFooter.Text = ""
            .EvenPage.RightFooter.Text = ""
            .FirstPage.LeftHeader.Text = ""
            .FirstPage.CenterHeader.Text = ""
            .FirstPage.RightHeader.Text = ""
            .FirstPage.LeftFooter.Text = ""
            .FirstPage.CenterFooter.Text = ""
            .FirstPage.RightFooter.Text = ""
        End With
        ActiveWindow.View = xlNormalView
    End Sub

  13. #13
    Registered User
    Join Date
    07-11-2012
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: Loop Macro Excluding 1 specific sheet

    Hi John,
    How can I combine the 2 macros to be run at the same time? Right now I see them as Page setup1 and Page setup2.

  14. #14
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Loop Macro Excluding 1 specific sheet

    Hi jaslake,

    I deleted a lot of code the macro recorded. Things that were set to "" and false statements. I see you kept everything in your version. Is there a reason for that? I am new to VBA too

    Thanks

  15. #15
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Loop Macro Excluding 1 specific sheet

    Hi fredlo2010
    I deleted a lot of code the macro recorded. Things that were set to "" and false statements. I see you kept everything in your version. Is there a reason for that?
    No, no reason...the code COULD USE rewriting but doesn't REQUIRE it...so I chose not to.

  16. #16
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Loop Macro Excluding 1 specific sheet

    Thanks for the input jaslake. I just wanted to make sure everything was optional.

    Thanks a lot

  17. #17
    Registered User
    Join Date
    07-11-2012
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: Loop Macro Excluding 1 specific sheet

    Can you please help me again? I need to shorten this macro since its really slow. Is it some how possible to select 39 tabs and perform print setup and do another print set up on the last tab? How do I post a new thread? I need help please.

  18. #18
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Loop Macro Excluding 1 specific sheet

    Hi norrie007
    The Code can be shortened but you're doing a lot of formatting in VBA and that's a slow process (in VBA). This Code is shortened but I have no clue if it does as you require or if the process will be faster because I 'm not working with your files such that I can see what you expect.
    Option Explicit
    Dim ws As Worksheet
    Sub PAGESETUP1()
        Dim i As Long
        Application.ScreenUpdating = False
        For i = Worksheets.Count To 3 Step -1
            Set ws = Worksheets(i)
            If Not ws.Name = "S-5000 Facilities" Then
                With ws.PageSetup
                    .PrintTitleColumns = "$G:$G"
                    .PrintArea = "$G:$X"
                    .LeftFooter = "&D - &T"
                    .CenterFooter = "&Z&F"
                    .RightFooter = "Page &P"
                    .PrintComments = xlPrintNoComments
                    .PrintQuality = 600
                    .CenterHorizontally = True
                    .Orientation = xlLandscape
                    .PaperSize = xlPaperLetter
                    .FirstPageNumber = xlAutomatic
                    .Order = xlDownThenOver
                    .FitToPagesWide = 1
                    .FitToPagesTall = 1
                    .PrintErrors = xlPrintErrorsDisplayed
                    .ScaleWithDocHeaderFooter = True
                End With
            End If
        Next
        Call PAGESETUP2
        Application.ScreenUpdating = True
    End Sub
    
    
    Sub PAGESETUP2()
        Sheets("S-5000 Facilities").Activate
        Set ws = ActiveSheet
        With ws
            .ResetAllPageBreaks
            .HPageBreaks(2).Location = Range("G72")
        End With
    
        With ws.PageSetup
            .PrintTitleRows = "$12:$21"
            .PrintTitleColumns = "$G:$G"
            .PrintArea = "$G:$X"
            .LeftFooter = "&D - &T"
            .CenterFooter = "&Z&F"
            .RightFooter = "Page &P"
            .PrintComments = xlPrintNoComments
            .PrintQuality = 600
            .CenterHorizontally = True
            .Orientation = xlLandscape
            .PaperSize = xlPaperLetter
            .FirstPageNumber = xlAutomatic
            .Order = xlDownThenOver
            .FitToPagesWide = 1
            .FitToPagesTall = 2
            .PrintErrors = xlPrintErrorsDisplayed
            .ScaleWithDocHeaderFooter = True
        End With
        ActiveWindow.View = xlNormalView
    End Sub
    Regarding this
    How do I post a new thread?
    The same way you started this one...it's really quite simple...enter the Forum...click on +Post New Thread.

    Regarding this
    is there a way to do a global print range by selecting all tabs instead of creating a loop macro?
    No clue...have you tried recording a Macro to do so?

  19. #19
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,981

    Re: Loop Macro Excluding 1 specific sheet

    Just select all the sheets you want to have the same format and record the settings you want.

    You'll get something like:

    Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = "Testing - Page &P - Header"
        .RightHeader = ""
        .LeftFooter = ""
        .CenterFooter = "Testing - Page &P - Footer"
        .RightFooter = ""
        .LeftMargin = Application.InchesToPoints(0.905511811023622)
        .RightMargin = Application.InchesToPoints(0.905511811023622)
        .TopMargin = Application.InchesToPoints(0.94488188976378)
        .BottomMargin = Application.InchesToPoints(0.94488188976378)
        .HeaderMargin = Application.InchesToPoints(0.511811023622047)
        .FooterMargin = Application.InchesToPoints(0.511811023622047)
        .PrintHeadings = False
        .PrintGridlines = False
        .PrintComments = xlPrintNoComments
        .PrintQuality = 600
        .CenterHorizontally = True
        .CenterVertically = True
        .Orientation = xlLandscape
        .Draft = False
        .PaperSize = xlPaperA4
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = False
        .Zoom = False
        .FitToPagesWide = 2
        .FitToPagesTall = 2
        .PrintErrors = xlPrintErrorsDisplayed
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .ScaleWithDocHeaderFooter = True
        .AlignMarginsHeaderFooter = True
        .EvenPage.LeftHeader.Text = ""
        .EvenPage.CenterHeader.Text = ""
        .EvenPage.RightHeader.Text = ""
        .EvenPage.LeftFooter.Text = ""
        .EvenPage.CenterFooter.Text = ""
        .EvenPage.RightFooter.Text = ""
        .FirstPage.LeftHeader.Text = ""
        .FirstPage.CenterHeader.Text = ""
        .FirstPage.RightHeader.Text = ""
        .FirstPage.LeftFooter.Text = ""
        .FirstPage.CenterFooter.Text = ""
        .FirstPage.RightFooter.Text = ""
    End With

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  20. #20
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Loop Macro Excluding 1 specific sheet

    Maybe I missed this part, but who's the final user? I have a slow macro too and there is no way for me to make it faster. Its just the way it is. What I did I used a message box to display that the macro was running and that i would take long...Somehow it helps me. After several months running that macro it doesn't seem so long.

    Will all respect and all credits go to him, I took the original code created by jaslake and cleaned some of the select, activate. Also added the msgbox. Tell me if it helps.

    Print Area.xlsm

  21. #21
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Loop Macro Excluding 1 specific sheet

    Here's an example using the example from post #26 with a progress bar to show you how long it's going to take to complete.

    Hope this helps.

    abousetta
    Attached Files Attached Files
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  22. #22
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Loop Macro Excluding 1 specific sheet

    Awesome abousetta. Its great how we implement each other's ideas to make a piece of code better and better.

  23. #23
    Registered User
    Join Date
    07-11-2012
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    48

    Re: Loop Macro Excluding 1 specific sheet

    Thanks all. There is no way to select all sheets and do a "set print area". Print options are limited when multiple sheets are selected.

  24. #24
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Loop Macro Excluding 1 specific sheet

    One thing you can do is only include in your code whatever is not standard to your Excel defaults. For example, the following code sets your header, footer, right and left margins.
        .LeftHeader = ""
        .CenterHeader = "Testing - Page &P - Header"
        .RightHeader = ""
        .LeftFooter = ""
        .CenterFooter = "Testing - Page &P - Footer"
        .RightFooter = ""
    Now if your default are empty header, footer, right and left margins then this should suffice:
        .CenterHeader = "Testing - Page &P - Header"
        .CenterFooter = "Testing - Page &P - Footer"
    Therefore, the run-time should be less.

    Hope this helps.

    abousetta

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1