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:

Some videos you may like

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Domski

Well-known Member
Joined
Jan 18, 2005
Messages
7,292
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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,142
Messages
5,599,971
Members
414,353
Latest member
ljhan

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
Top