Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Modify code for multiple sheets-Help defining array

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Modify code for multiple sheets-Help defining array

If I understand your question correctly, I think this code will do what you
want...

Dim X As Long
ActiveSheet.UsedRange.Rows.Hidden = False
For X = 3 To 5
With Worksheets(X).Range("H1:H100")
Do Until .Find("No") Is Nothing
.Find("No").EntireRow.Delete
Loop
Next

Rick


"ToddEZ" wrote in message
...
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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Modify code for multiple sheets-Help defining array

Whoops! I left out the End With statement...

Dim X As Long
ActiveSheet.UsedRange.Rows.Hidden = False
For X = 3 To 5
With Worksheets(X).Range("H1:H100")
Do Until .Find("No") Is Nothing
.Find("No").EntireRow.Delete
Loop
End With
Next

Rick


"Rick Rothstein (MVP - VB)" wrote in
message ...
If I understand your question correctly, I think this code will do what
you want...

Dim X As Long
ActiveSheet.UsedRange.Rows.Hidden = False
For X = 3 To 5
With Worksheets(X).Range("H1:H100")
Do Until .Find("No") Is Nothing
.Find("No").EntireRow.Delete
Loop
Next

Rick


"ToddEZ" wrote in message
...
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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Modify code for multiple sheets-Help defining array

I guess I should have been clearer in my question. The sheet names actually
vary (not "sheet 1, sheet 2, etc"). They are SOAA, SOC, SAR, Checklist, and
a few others. Is there a way I can select these sheets and then run the
marco for each sheet?

Thanks agian.

"Rick Rothstein (MVP - VB)" wrote:

If I understand your question correctly, I think this code will do what you
want...

Dim X As Long
ActiveSheet.UsedRange.Rows.Hidden = False
For X = 3 To 5
With Worksheets(X).Range("H1:H100")
Do Until .Find("No") Is Nothing
.Find("No").EntireRow.Delete
Loop
Next

Rick


"ToddEZ" wrote in message
...
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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Modify code for multiple sheets-Help defining array

First off, use the modified code I posted under my original message. Now,
the number 3 through 5 which I am using in my code do not correspond to
sheet names, they are the index numbers of the sheet name tabs with the
left-most one having an index number of 1, the second left-most one having
an index number of 2 and so on... no matter what "names" appear on those
tabs. I structured my code that way because you said "macro to operate
across sheets 3, 4, & 5 rather than just sheet 1". Anyway, there is a minor
problem with the code I initially posted... the "unhide" statement is in the
wrong place. Here is the modified code you should use if you stick with the
tab sheet ordering I just described.

Dim X As Long
For X = 3 To 5
With Worksheets(X).Range("H1:H100")
Worksheets(X).UsedRange.Rows.Hidden = False
Do Until .Find("No") Is Nothing
.Find("No").EntireRow.Delete
Loop
End With
Next

So, if you have listed your names in order, then my code would process them
as long as SOAA is the third tab over from the left, SOC is the fourth tab
over from the left and SAR is the fifth tab over from the left. If that is
how your tabs are positioned, then try out the modified code I posted.

However, if this is not how your tabs are positioned, then you can use this
more generic version of the above...

Dim X As Long
Dim MySheets() As String
MySheets = Split("SOAA,SOC,SAR", ",")
For X = 0 To UBound(MySheets)
Worksheets(MySheets(X)).UsedRange.Rows.Hidden = False
With Worksheets(MySheets(X)).Range("H1:H100")
Do Until .Find("No") Is Nothing
.Find("No").EntireRow.Delete
Loop
End With
Next

where you declare your sheet names inside the Split statement as shown.

Rick


"ToddEZ" wrote in message
...
I guess I should have been clearer in my question. The sheet names
actually
vary (not "sheet 1, sheet 2, etc"). They are SOAA, SOC, SAR, Checklist,
and
a few others. Is there a way I can select these sheets and then run the
marco for each sheet?

Thanks agian.

"Rick Rothstein (MVP - VB)" wrote:

If I understand your question correctly, I think this code will do what
you
want...

Dim X As Long
ActiveSheet.UsedRange.Rows.Hidden = False
For X = 3 To 5
With Worksheets(X).Range("H1:H100")
Do Until .Find("No") Is Nothing
.Find("No").EntireRow.Delete
Loop
Next

Rick


"ToddEZ" wrote in message
...
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




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Modify code for multiple sheets-Help defining array

Thanks Rick!

"Rick Rothstein (MVP - VB)" wrote:

First off, use the modified code I posted under my original message. Now,
the number 3 through 5 which I am using in my code do not correspond to
sheet names, they are the index numbers of the sheet name tabs with the
left-most one having an index number of 1, the second left-most one having
an index number of 2 and so on... no matter what "names" appear on those
tabs. I structured my code that way because you said "macro to operate
across sheets 3, 4, & 5 rather than just sheet 1". Anyway, there is a minor
problem with the code I initially posted... the "unhide" statement is in the
wrong place. Here is the modified code you should use if you stick with the
tab sheet ordering I just described.

Dim X As Long
For X = 3 To 5
With Worksheets(X).Range("H1:H100")
Worksheets(X).UsedRange.Rows.Hidden = False
Do Until .Find("No") Is Nothing
.Find("No").EntireRow.Delete
Loop
End With
Next

So, if you have listed your names in order, then my code would process them
as long as SOAA is the third tab over from the left, SOC is the fourth tab
over from the left and SAR is the fifth tab over from the left. If that is
how your tabs are positioned, then try out the modified code I posted.

However, if this is not how your tabs are positioned, then you can use this
more generic version of the above...

Dim X As Long
Dim MySheets() As String
MySheets = Split("SOAA,SOC,SAR", ",")
For X = 0 To UBound(MySheets)
Worksheets(MySheets(X)).UsedRange.Rows.Hidden = False
With Worksheets(MySheets(X)).Range("H1:H100")
Do Until .Find("No") Is Nothing
.Find("No").EntireRow.Delete
Loop
End With
Next

where you declare your sheet names inside the Split statement as shown.

Rick


"ToddEZ" wrote in message
...
I guess I should have been clearer in my question. The sheet names
actually
vary (not "sheet 1, sheet 2, etc"). They are SOAA, SOC, SAR, Checklist,
and
a few others. Is there a way I can select these sheets and then run the
marco for each sheet?

Thanks agian.

"Rick Rothstein (MVP - VB)" wrote:

If I understand your question correctly, I think this code will do what
you
want...

Dim X As Long
ActiveSheet.UsedRange.Rows.Hidden = False
For X = 3 To 5
With Worksheets(X).Range("H1:H100")
Do Until .Find("No") Is Nothing
.Find("No").EntireRow.Delete
Loop
Next

Rick


"ToddEZ" wrote in message
...
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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Modify macro code to export multiple cell contents to multiple Text Files [email protected] Excel Programming 3 October 14th 06 08:26 AM
Defining a function to use multiple places in code Barb Reinhardt Excel Programming 7 August 28th 06 08:22 PM
Array, multiple sheets Ronny[_3_] Excel Programming 3 January 17th 06 06:43 PM
Printing multiple sheets in an array rwong Excel Programming 3 July 28th 05 08:29 AM
selecting multiple sheets by use of an array? anhjan[_3_] Excel Programming 3 April 8th 04 01:58 AM


All times are GMT +1. The time now is 08:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"