Need macro to run on all sheets not just active.

jwindholz2725

Board Regular
Joined
Sep 20, 2011
Messages
94
Can anybody help please? I have a code that hides lines for me that = 0. (see below) But this only works on the active sheet. How can I make it run this code on all sheets?

Sub HideLines()
Application.ScreenUpdating = False
Dim c As Range
For Each c In Range("Q6:Q431")
If c.Value = 0 Then
Rows(c.Row).Hidden = True
Else
Rows(c.Row).Hidden = False
End If
Next c
Application.ScreenUpdating = True
ActiveSheet.ResetAllPageBreaks
With ActiveSheet.PageSetup
.Zoom = 100
End With
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Try this
Code:
Sub HideLines()
Application.ScreenUpdating = False
Dim c As Range
 For Each ws In Sheets
        ws.Activate
For Each c In Range("Q6:Q431")
If c.Value = 0 Then
Rows(c.Row).Hidden = True
Else
Rows(c.Row).Hidden = False
End If
Next c
Application.ScreenUpdating = True
ActiveSheet.ResetAllPageBreaks
With ActiveSheet.PageSetup
.Zoom = 100
End With
Next ws
End Sub
 
Upvote 0
This worked great but I had one issue on my part. This should be ran on certain sheets but not all. Is there a way to put a range say tab "<" through tab ">"? Then I could run the code on just the tabs that needed it.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,716
Members
452,939
Latest member
WCrawford

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