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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
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,224,898
Messages
6,181,625
Members
453,058
Latest member
rmd0725

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