View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JE McGimpsey JE McGimpsey is offline
external usenet poster
 
Posts: 4,624
Default Modify code for multiple sheets-Help defining array

One way:

Dim rCell As Range
Dim i As Long
For i = 1 To 5
If i < 2 Then
With Worksheets(i)
.Rows.Hidden = False
For Each rCell In .Range("H1:H100")
With rCell
.EntireRow.Hidden = (.Text = "No")
End With
Next rCell
End With
End If
Next i


Alternatively:

Dim ws As Worksheet
Dim rCell As Range

For Each ws In Worksheets(Array( _
"Sheet1", "Sheet3", "Sheet4", "Sheet5"))
ws.Rows.Hidden = False
For Each rCell In ws.Range("H1:H100")
With rCell
.EntireRow.Hidden = (.Text = "No")
End With
Next rCell
Next ws




In article ,
ToddEZ wrote:

Hi,

I need some help modifying this "hide row" macro to operate accross sheets
3, 4, & 5 rather than just sheet 1. I realize that I can just copy the same
code several times (changing the sheet reference) but I was hoping there is
an eaiser way to define a multiple sheet array for this.

Thanks in advance,

What is the Dim cell As Range
With ActiveSheet.UsedRange
.Rows.Hidden = False
For Each cell In Worksheets("Sheet1").Range("h1:h100")
If cell.Text = "No" Then cell.EntireRow.Hidden = True
Next cell
End With