Hide Rows on All Sheets Based on Value

Simple85

New Member
Joined
Aug 8, 2018
Messages
2
Hi,
I currently have a VBA script that hides the rows on a worksheet if that row has the text "Hide" within the range A5:A100. I am trying to adapt it to automatically do this on every worksheet at once.

This is where I am at (which is not working):



Sub Hide_Zero_Rows()
Dim sht As Worksheet
For Each sht In Worksheets
For Each cell In sht.Range("A5:100")
If cell.Value = "Hide" Then
cell.EntireRow.Hidden = True
Else
cell.EntireRow.Hidden = False
End If
Next cell
Next sht
End Sub

Your help would be appreciated!
Cheers
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try the below code,

Code:
Sub Hide_Zero_Rows()
    Dim Rng As Range
    Dim Sht As Worksheet
    For Each Sht In ThisWorkbook.Sheets
        Sht.Range("A5:A100").EntireRow.Hidden = False
        For Each Rng In Sht.Range("A5:A100")
            If UCase(Rng.Value) = "HIDE" Then Rng.EntireRow.Hidden = True
        Next Rng
    Next Sht
End Sub
 
Last edited:
Upvote 0
Hi & welcome to MrExcel.
How about
Code:
Sub Hide_Zero_Rows()
   Dim sht As Worksheet, Cell As Range
   For Each sht In Worksheets
      For Each Cell In sht.Range("A5:A100")
         Cell.EntireRow.Hidden = Cell.Value = "Hide"
      Next Cell
   Next sht
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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