Adjust individual sheet margins to a master sheet

claudehollett

Board Regular
Joined
Dec 11, 2003
Messages
89
I need to adust all margins for a series of worksheets to the margins of an existing "Master" sheet. What code will do this? Thank you, Claude
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Macropheliac

Board Regular
Joined
Aug 26, 2005
Messages
165
I think this will do it. It is untested.
Code:
Sub Adjust_Margins()
Dim Mysheet As Worksheet
Dim Sht As Worksheet

Set Mysheet = Sheets("Master")  'Adjust as necessary

For Each Sht In ActiveWorkbook.Sheets
        With Sht.PageSetup
                .LeftHeader = Mysheet.PageSetup.LeftHeader
                .CenterHeader = Mysheet.PageSetup.CenterHeader
                .RightHeader = Mysheet.PageSetup.CenterHeader
                .LeftFooter = Mysheet.PageSetup.LeftFooter
                .CenterFooter = Mysheet.PageSetup.CenterFooter
                .RightFooter = Mysheet.PageSetup.RightFooter
                .LeftMargin = Mysheet.PageSetup.LeftMargin
                .RightMargin = Mysheet.PageSetup.RightMargin
                .TopMargin = Mysheet.PageSetup.TopMargin
                .BottomMargin = Mysheet.PageSetup.BottomMargin
                .HeaderMargin = Mysheet.PageSetup.HeaderMargin
                .FooterMargin = Mysheet.PageSetup.FooterMargin
        End With
Next Sht

End Sub
 

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,454
If you want to set the margins of all worksheets in the workbook the same as the Master sheet's then Macropheliac should have you ready to go.
If you only want to do it to specified sheets then something like this should do it.
Code:
Sub SetMarginsDemo()
Dim ThisSht As Worksheet

For Each ThisSht In ThisWorkbook.Worksheets
  Select Case ThisSht.Name
    Case "Sheet2", "Sheet4", "Sheet6", "Sheet8"
      With ThisSht.PageSetup
        .TopMargin = Sheets("Master").PageSetup.TopMargin
        .BottomMargin = Sheets("Master").PageSetup.BottomMargin
        .Leftmargin = Sheets("Master").PageSetup.Leftmargin
        .RightMargin = Sheets("Master").PageSetup.RightMargin
      End With
  End Select
Next ThisSht

End Sub
 

Forum statistics

Threads
1,136,309
Messages
5,674,999
Members
419,541
Latest member
freddyboots

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
Top