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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,525
Messages
6,120,051
Members
448,940
Latest member
mdusw

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