Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hiding rows on specified sheets

Status
Not open for further replies.

sedgely

Technical User
Feb 21, 2002
406
GB
i have the following code (thanks to an earlier post)that hides rows based on the value of cells in a specified column.
Code:
Sub hideRows()
Application.ScreenUpdating = False

    Dim stratRow As Integer, endRow As Integer
    Dim targetCol As String, x As Integer
    
    startRow = 1
    endRow = 200
    targetCol = "hk"
    
        For x = startRow To endRow
            If Range(targetCol & x).Value = 0 Then
               Range(targetCol & x).EntireRow.Hidden = True
            End If
        Next x
Application.ScreenUpdating = True

End Sub
This works fine, but i now want to perfprm this on other sheets in the workbook, i have a list of the sheetnames of the sheeets i need to perform this on in sheet 1. how can i amend the code so that it will look at the list of sheet names and then run the hideRows macro on each of the named sheets?

Cheers, Craig
Si fractum non sit, noli id reficere
 
Perhaps something like this ?
Sub hideRows()
Application.ScreenUpdating = False
Dim stratRow As Integer, endRow As Integer
Dim targetCol As String, x As Integer
Dim shName
For Each shName in Array("Sheet1", "Sheet2", Sheet3")
startRow = 1
endRow = 200
targetCol = "hk"
For x = startRow To endRow
If Worksheets(shName).Range(targetCol & x).Value = 0 Then
Worksheets(shName).Range(targetCol & x).EntireRow.Hidden = True
End If
Next x
Next
Application.ScreenUpdating = True

End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PH thanx for that it worked a treat, however, one quick query...
because there are quite a few sheets and the sheets change i have listed the relevant sheet names on sheet1 can i look at a list to find the names of sheets instead of using
Code:
For Each shName in Array("Sheet1", "Sheet2", Sheet3")

Cheers, Craig
Si fractum non sit, noli id reficere
 
yup

For each shName in Range("A1:A100")

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Thanks guys
that's got it sorted now.

Cheers, Craig
Si fractum non sit, noli id reficere
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top