Format macro

kizzie37

Well-known Member
Joined
Oct 23, 2007
Messages
575
Office Version
  1. 365
I have the below macro i recorderd to format sheets in excel, I get an error on the second line of this sheet - 1004 Object defined error. Its no different to any of the other sheets, so i dont understand what the error is.

Sheets("ASSUMPTIONS").Select
Range("A1:H1").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$H$78"


Can anyone help?
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Try this.
Code:
With Sheets("ASSUMPTIONS")
 
     LastRow = .Range("A" & Rows.Count).End(xlUp).Row
 
     Set rng = Sheets("ASSUMPTIONS").Range("A1:H" & LastRow)
 
     .PageSetup.PrintArea = rng.Address
 
End With
Using the macro recorder is a good idea, especially to get the general syntax, but the generated code always needs a tweak or two.
 
Upvote 0
Thanks, both work great, it woul be helpful to udnerstand why a recorded macro, doesnt work when you run it back?. Would like to understand so I know for the future
 
Upvote 0
Well I suppose you could say it's because it's a recorded macro, also it does what it says - ie records whatever you fo.

It's a great tool but it can't perform magic, it's very rarely that the generated code will be your final code.

Use it as a guide to get the right syntax etc.
 
Upvote 0

Forum statistics

Threads
1,213,565
Messages
6,114,337
Members
448,568
Latest member
Honeymonster123

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