Hidind rows conditionally

H

Henri

I need to scan rows in a range and hide them according to
the value of one of their columns.

Basically:

For Cell= E1 to E650
if E(XX)=0 hide row where E(XX) is.
Next

Thanks in advance
 
F

Frank Kabel

Hi
try:
Sub hide_rows()
Dim RowNdx As Long
Dim LastRow As Long
application.screenupdating=false
LastRow = ActiveSheet.Cells(Rows.Count, "E").End(xlUp).row
For RowNdx = LastRow To 1 Step -1
if cells(RowNdx,"E").value=0 then
Rows(RowNdx).hidden = True
End If
Next RowNdx
application.screenupdating=true
End Sub
 
R

Ron de Bruin

Try this Henri

Sub Example2()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveSheet
.DisplayPageBreaks = False
StartRow = 1
EndRow = 650
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "E").Value) Then
'Do nothing, This avoid a error if there is a error in the cell

ElseIf .Cells(Lrow, "E").Value = "0" Then .Rows(Lrow).Hidden = True

End If
Next
End With
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub


My new add-in have this option also
http://www.rondebruin.nl/easyfilter.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top