Unhide or hide rows based on cell values in each row

jkehoe

New Member
Joined
Feb 8, 2009
Messages
7
Hi all - my first post here.

I have a worksheet with a series of sequential numbers in Column F, typically running from about 25 or 30 in Row 6, and increasing by 1 in each row below that, to a maximum number in Row 85. I'd like to hide the rows in which the number in Column F is greater than 90. The procedure needs to run whenever the sheet is calculated. The values in the column can change based on either of 2 inputs on another sheet, so I also need the procedure to unhide rows in which the number is 90 or less. The code I have so far is:

VBA Code:
Private Sub Worksheet_Calculate()
    Dim Cl As Range
    For Each Cl In Range("F6:F85")
        Cl.EntireRow.Hidden = False
        Cl.EntireRow.Hidden = Cl.Value > 90
    Next Cl
End Sub

... But it's not working. I get an "application-defined or object-defined" error. Can anyone see what I'm missing here?

BTW - I've also tried calling this procedure from Sheet1 (using the Worksheet_Change event), but I can't get it to run the code on Sheet2. To be clear - there are 2 inputs on Sheet1, and I want Sheet2's row-unhiding/hiding procedure to run if either input changes.
 
I suspect that the sheet was recalculating every time a row was hidden.
By turning events off it prevents the code from being called constantly.
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,922
Members
449,094
Latest member
teemeren

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