Help Please Marco Needed for Margins and Cursor in A1

cSciFiChick

New Member
Joined
Jul 31, 2014
Messages
42
I have posted this before but the marco did not do what I needed. I would be so grateful if someone would help me. I process reports at my work while they are all different meaning different numbers of columns and rows of data and number of tabs etc. They each need to have three things before I send them.


  • The data needs to be scrolled to the top and the cursor needs to be in A1
  • The margins needs to be set to Top: .25 Bottom: .25 Left: .17 Right: .22 Header: .3 Footer: .3
  • And the Print Area must be set to only include the data on that table. Normally I just highlight the whole page and under Page Layout I use Print Area-Set Print Area I do this on each tab. I have been told that it impossible in a macro because not every tab or report is going to have the same area of data.

So I am fine if I can just get the top two things in a Macro that will set those for every tab in the workbook.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
See if this does what you want. It loops through each sheet of the active workbook and applies your changes

Code:
Sub x()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
    With ws
        .Cells(1, 1).Select
        
        With .PageSetup
            .LeftMargin = Application.InchesToPoints(6.69291338582677E-02)
            .RightMargin = Application.InchesToPoints(8.66141732283465E-02)
            .TopMargin = Application.InchesToPoints(9.84251968503937E-02)
            .BottomMargin = Application.InchesToPoints(9.84251968503937E-02)
            .HeaderMargin = Application.InchesToPoints(0.118110236220472)
            .FooterMargin = Application.InchesToPoints(0.118110236220472)
            .PrintArea = ActiveCell.CurrentRegion.Address
        End With
        
    End With
Next ws
End Sub
 
Upvote 0
See if this does what you want. It loops through each sheet of the active workbook and applies your changes

Code:
Sub x()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
    With ws
        .Cells(1, 1).Select
        
        With .PageSetup
            .LeftMargin = Application.InchesToPoints(6.69291338582677E-02)
            .RightMargin = Application.InchesToPoints(8.66141732283465E-02)
            .TopMargin = Application.InchesToPoints(9.84251968503937E-02)
            .BottomMargin = Application.InchesToPoints(9.84251968503937E-02)
            .HeaderMargin = Application.InchesToPoints(0.118110236220472)
            .FooterMargin = Application.InchesToPoints(0.118110236220472)
            .PrintArea = ActiveCell.CurrentRegion.Address
        End With
        
    End With
Next ws
End Sub

I am getting an error. "Run-time error '1004': Select method of Range class failed.
 
Upvote 0
Try adding this line as shown
Code:
    With ws
        [COLOR=#ff0000]ws.Activate[/COLOR]
        .Cells(1, 1).Select
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,173
Members
453,021
Latest member
Justyna P

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