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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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,214,575
Messages
6,120,334
Members
448,956
Latest member
Adamsxl

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