Hide rows if they equal...

R

Rutgers_Excels

I want to use VB to write a code that will allow me to hide rows in the
range A1:A100 if they say "not used". Any help?

Thanks,

Brian
 
R

Ron de Bruin

Hi Brian

One way :
You can use Data>AutoFilter

Choose custom in the list and use
does not equal "not used"
 
R

Rutgers_Excels

Ron,

That is the effect I want to get, however, i would like to know i
there is a "cleaner" looking way to accomplish this same task usin
visual basic. I have created a database that will be sent to othe
funtional departments and I don't want them to be able to mess aroun
with the filtering. I would like to use a code that is similar t
this....

Sub HideRows()
Range("A1:A100").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Hidden = True
End Sub

...but instead of hiding blank rows I'd like to be able to hide row
that say "not used".

Thanks for your hel
 
R

Ron de Bruin

Try this

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 = 100
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "A").Value) Then
'Do nothing, This avoid a error if there is a error in the cell

ElseIf .Cells(Lrow, "A").Value = "not used" Then .Rows(Lrow).Hidden = True

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

Rutgers_Excels

That works perfectly. Did exactly what I wanted it to do.

Thank you very much for you help!

Bria
 
Top