Hide Rows in a Range Based on Cell Value

HotNumbers

Well-known Member
Joined
Feb 14, 2005
Messages
728
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

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.

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
18,069
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Is col D empty? If not, what's the first empty column in the worksheet?
 
Upvote 0

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
18,069
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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,191,317
Messages
5,985,944
Members
439,991
Latest member
NCWalker

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