Dynamic hiding rows

sue9685

New Member
Joined
Dec 10, 2019
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi guys,
I have a little problem with my vba formula.
I need it to work in a way, that if the cell in the columns B (cells B9:B65) contains "hide" , the entire row should be hidden. I was using the code below:

Sub Hide_Rows()
Dim c As Range
For Each c In Range("B9:B65").Cells
If c.Value = "Hide" Then
c.EntireRow.Hidden = True
End If
End Sub

The code needs to work dynamically - the values in column B are based on a formula from another sheet and are often updated. The idea is that macro runs after clicking a button and the search can be re-done anytime. The problem is that the code runs correctly once, but then it doesn't not search among the hidden rows from the previous search..
Can this be somehow fixed?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi & welcome to MrExcel.
How about
VBA Code:
Sub Hide_Rows()
    Dim Cl As Range
    For Each Cl In Range("B9:B65")
        Cl.EntireRow.Hidden = Cl.Value = "Hide"
    Next Cl
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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