Hide Rows in a Range Based on Cell Value

HotNumbers

Well-known Member
Joined
Feb 14, 2005
Messages
732
I need a quick way to hide rows based on cell value in a column without using a loop. my current code is a loop and is too slow. PLEASE HELP

Column C is my range and if a cell value has a "x" then i need that row hidden. Here is my current code...

''''Hides Rows

For Each WS In ThisWorkbook.Worksheets
WS.Rows("1:2500").EntireRow.Hidden = False
Dim cp As Range
Dim a As Integer
For a = 1 To 2500
WS.Cells(a, 3).EntireRow.Hidden = WS.Cells(a, 3).Value = "x"
Next a
Next WS
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Is col D empty? If not, what's the first empty column in the worksheet?
 
Upvote 0
Is col D empty? If not, what's the first empty column in the worksheet?
Assuming there's a column that's empty on each worksheet in your workbook (I assumed col D in the code below, but you can change it to suit - see commented line), try this:
Code:
Sub HideRowsOnAllWkshts()
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
WS.Rows("1:2500").EntireRow.Hidden = False
Dim cp As Range
Dim a As Integer
Application.ScreenUpdating = False
WS.Range("D1:D2500") = WS.Range("C1:C2500").Value  'Change col D to any empty column
With WS.Range("D1:D2500")
    .Replace "x", "#N/A", xlWhole
    On Error Resume Next
    With .SpecialCells(xlCellTypeConstants, xlErrors)
        .EntireRow.Hidden = True
    End With
    On Error GoTo 0
    .ClearContents
End With
Application.ScreenUpdating = True
Next WS
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,789
Messages
6,121,593
Members
449,038
Latest member
Arbind kumar

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