Select range then print same range in all worksheets

jnbrewer69

New Member
Joined
Jun 12, 2007
Messages
10
Hi,

I have got a macro that will print a range on active worksheet.
I need the code or a new macro to then loop this thru all work sheets in workbook

see code below

-----------------------------------------------------------------------
Sub printtotal()
'
' printtotal Macro
' Macro recorded 04/07/2007 by jbrewer
'
' Keyboard Shortcut: Ctrl+Shift+Q
'
ActiveSheet.Unprotect
Range("Z1:AL46").Select
Selection.PrintOut Copies:=1, Collate:=True
ActiveWindow.ScrollRow = 8
ActiveWindow.ScrollRow = 7
ActiveWindow.ScrollRow = 6
ActiveWindow.ScrollRow = 4
ActiveWindow.ScrollRow = 3
ActiveWindow.ScrollRow = 2
ActiveWindow.ScrollRow = 1
Range("A1").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

End Sub
------------------------------------------------
Thanks in advance

Johnny B
Code:
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
To loop through each sheet:
Code:
Dim wksheet as worksheet
For each wksheet in worksheets
wksheet.select
'Put your code here
Next wksheet

HTH,
~Gold Fish

P.S. Your above code can be simplified to:
Code:
ActiveSheet.Unprotect 
Range("Z1:AL46").PrintOut Copies:=1, Collate:=True 
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
 
Upvote 0
Sorry I'm a noob where do i put the code lol

Thanks for you help where do i put the code. I know its something i'm doing wrong

this give me an error 1004
" methodselect object failed

---------------------------------------------------------
Sub Printotal()


Dim wksheet As Worksheet
For Each wksheet In Worksheets
wksheet.Select
ActiveSheet.Unprotect
Range("Z1:AL46").PrintOut Copies:=1, Collate:=True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Next wksheet

End Sub
 
Upvote 0
Code:
Sub Printotal() 
Dim wksheet As Worksheet 
For Each wksheet In Worksheets 
wksheet.Range("Z1:AL46").PrintOut Copies:=1, Collate:=True 
Next wksheet 
End Sub

Not sure why its erroring, that looks right... Does the code work with out unprotecting like above? or maybe:

Code:
Sub Printotal() 
Dim wksheet As Worksheet 
For Each wksheet In Worksheets 
With wksheet
.Unprotect 
.Range("Z1:AL46").PrintOut Copies:=1, Collate:=True 
.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End With
Next wksheet 
End Sub

HTH,
~Gold Fish
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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