PDA

View Full Version : Hide rows based on particular cell value



zale86
02-10-2009, 01:37 PM
I want to hide all rows beginning with row 3 that do not match the value of cell A:1. unless it is blank. In this case no rows will be hidden. A:1 will always have a 4 digit number when it is not blank.
Can someone help? I've been searching and can't get anywhere.

MaximS
02-10-2009, 06:19 PM
try that:


Sub Hidder()
Dim LRow As Long
'This will check for last used row
LRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
If Cells(1, 1).Value <> "" Then
For i = 3 To LRow
If Cells(i, 1).Value = Cells(1, 1).Value And Rows(i).Hidden = False Then
Rows(i).Hidden = True
End If
Next i
End If
End Sub

mdmackillop
02-11-2009, 06:40 AM
Option Explicit
Sub Hidder()
Dim LRow As Long, i As Long
LRow = Cells(Rows.Count, 1).End(xlUp).Row
'Unhide all rows
Rows.Hidden = False
If Cells(1, 1).Value <> "" Then
For i = 2 To LRow
If Left(Cells(i, 1), 1) = 3 And Cells(i, 1).Value <> Cells(1, 1) Then
Rows(i).Hidden = True
End If
Next i
End If
End Sub