exclude sheets based on value

bak

New Member
Joined
Mar 3, 2011
Messages
26
I have a l macro that performs on all sheets, now I want to exclude a few sheets based on cell value. How can I fix that?
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Dim Rng As String
Dim Wks As Worksheet
Rng = "$A$2:$N66"
For Each ws In Worksheets
With ws.PageSetup
.PrintArea = Rng
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
Next ws
ActiveWorkbook.PrintOut Copies:=1, Collate:=True
End Sub

exclude sheet if cel A300 isn't yes
 
Upvote 0
You miss spelled on of your references and you have the activeworkbook set to print, so you would have to change the code to print each sheet, to check it out what I have included is to give you a message box for each sheet that is being printed, test it on a workbook with a couple of sheets and if it works the way you want just comment out the msgbox:

Sub checkSheet()
Dim ws As Worksheet
Dim Rng As String
Rng = "$A$2:$N66"
For Each ws In Worksheets
If ws.Range("A300") = "Yes" Then
With ws.PageSetup
.PrintArea = Rng
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
ws.PrintOut copies:=1
MsgBox ws.Name
End If
Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,152
Members
452,891
Latest member
JUSTOUTOFMYREACH

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