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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

goldfish

Well-known Member
Joined
Aug 23, 2005
Messages
712
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

jnbrewer69

New Member
Joined
Jun 12, 2007
Messages
10
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

goldfish

Well-known Member
Joined
Aug 23, 2005
Messages
712
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,186,926
Messages
5,960,595
Members
438,486
Latest member
ncc84330

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