Hide rows across multiple worksheets based on cell value

Sylvia C

New Member
Joined
Apr 2, 2018
Messages
3
Hi. I would like to hide rows across multiple worksheets based on cell value. I have a VBA code that works on individual sheets in my workbook, but cannot figure out the code to apply it to multiple (13 and counting) worksheets without clicking run 13 times. I have looked through a lot of threads and tried to change the data to work for my situation, but cannot figure it out. (I have a separate code to unhide all rows with 1 click. Not sure if there's a way to make unhidden cells the default). Any help would be appreciated. Here is the code I currently have:

Sub HideRows()
Application.ScreenUpdating = False
Application.Calculation = xlManual

For Each c In Range("B8:B26")
If c.Value = 0 And c.Value <> "" Then Rows(c.Row).Hidden = True
Next

Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Add a loop to cycle through each worksheet

Code:
Sub HideRows()
Application.ScreenUpdating = False
Application.Calculation = xlManual
Dim ws As Worksheet
For Each ws In Worksheets
For Each c In Range("B8:B26")
If c.Value = 0 And c.Value <> "" Then Rows(c.Row).Hidden = True
Next c
Next ws


Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Hi & welcome to MrExcel.
How about
Code:
Sub HideRows()
   Dim c As Range
   Dim Ws As Worksheet
Application.ScreenUpdating = False
Application.Calculation = xlManual
   For Each Ws In Worksheets
      For Each c In Ws.Range("B8:B26")
         If c.Value = 0 And c.Value <> "" Then Ws.Rows(c.Row).Hidden = True
      Next
   Next Ws
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,516
Messages
6,125,284
Members
449,218
Latest member
Excel Master

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