Hide Rows Based On Cell Value

nehpets12

Active Member
Joined
Feb 22, 2002
Messages
453
I am using this code


Private Sub Worksheet_Activate()
Dim myRg As Range

'Change the [A1], [A65536] to your range
Set myRg = Range([B1].End(xlDown), [B65536].End(xlUp))

On Error Resume Next
Set myRg = myRg.SpecialCells(4)
If Err = 0 Then
myRg.EntireRow.Hidden = True
Else
MsgBox "No blanks"
End If
Set myRg = Nothing
End Sub


This works Very fast

On another sheet I would like to add a formula in column H That puts a 1 in rows I want to keep and "" in rows I want to hide how do I change Set myRg = myRg.SpecialCells(4)
 
Last edited:

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Maybe:

Code:
Private Sub Worksheet_Activate()
Dim myRg As Range, lastRow As Long
Application.Calculation = xlCalculationManual
lastRow = Cells(Rows.Count, 8).End(xlUp).Row
For Each myRg In Range("H2:H" & lastRow)
If myRg.Value = 1 Then
    
    myRg.EntireRow.Hidden = False
Else
    myRg.EntireRow.Hidden = True
End If
Next myRg
Application.Calculation = xlCalculationAutomatic
End Sub

Hope it helps,

Dom
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

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