View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Harald Staff Harald Staff is offline
external usenet poster
 
Posts: 1,327
Default Macro to hide multiple rows

Hi

You will have to loop cell by cell for this, but it's easy and fast:

Sub test()
Dim R As Range, Cel As Range
Set R = Range("A1:M300")
For Each Cel In R
If Cel.Value = "Cat" Then _
Cel.EntireRow.Hidden = True
Next
End Sub

HTH. Best wishes Harald

"Minh" skrev i melding
...
Hi,

I am writing a macro at the moment that hides a row given
a certain criteria is met. However, at the moment I have
had to do this on a row by row basis:

e.g.
If A8 = Cat Then
Rows("8:8").Select
Selection.EntireRow.Hidden = True
End If
If A9 = Cat Then
Rows("9:9").Select
Selection.EntireRow.Hidden = True
End If

etc....

Is there a way to do this to a range of cells rather than
on a cell by cell basis?

Thanks heaps.