Hide rows that equal 0

meangreen

Board Regular
Joined
Jan 29, 2007
Messages
169
In R25:R68 I have a formula that reluts in a "1" or a "0". The formula in R25 would be this: =if(A25<=$B$7,1,0). The formula in R26 would be the same but would reference A26 and so on. Basically, if any cell in A25:A68 is less than B7 then the corresponding cell in R25:R68 will be 1. If greater than it will equal 0.

Now I want to create a macro that will hide the rows from 25 thru 68 that have a 0 in coulmn R. They would also need to unhide as B7 will be changing all of the time. Any ideas?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Untested, but how about:

Code:
Dim lRow As Long

'loop through rows 25-68
For lRow = 25 To 68
    'if col A of row <= B7
    If Cells(lRow, 1) <= Range("B7") Then
        'unhide row
        Rows(lRow).Hidden = False
    Else
        'hide row
        Rows(lRow).Hidden = True
    End If
Next lRow
 
Upvote 0
That almost works, but it's not hiding/unhiding when I change the value in B7. I have to manually run the macro to make it work.
 
Upvote 0
Is there a way to adjust the code above so that any time the value in B7 changes the appropriate rows will hide/unhide? Currently I would have to create a button or something for it to work, but I would really like it to be automatic.

I don't know if it matters but B7 is a drop down list.
 
Upvote 0
You could put the code in a worksheet_change event. And just check if the target cell is "$B$7"

Maybe try something like this, I didn't test it thoguh:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Address = "$B$7" Then
Dim lRow As Long
'loop through rows 25-68
For lRow = 25 To 68
    'if col A of row <= B7
    If Cells(lRow, 1) <= Range("B7") Then
        'unhide row
        Rows(lRow).Hidden = False
    Else
        'hide row
        Rows(lRow).Hidden = True
    End If
Next lRow
End If
Application.EnableEvents = True
End Sub
Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,214,399
Messages
6,119,279
Members
448,884
Latest member
chuffman431a

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