Exclude specific sheets from a macro

Klb1503

Board Regular
Joined
Jul 10, 2006
Messages
67
Hi,

I have the macro below and it works ok, however it currently looks at all the worksheets in the workbook and I would like to exclude the last 5 worksheets - is there a way to do this please?

Thanks
Karen


Sub Hide_Columns_Containing_Value()
Application.ScreenUpdating = False

Dim WS As Worksheet
Dim X As Range

For Each WS In ThisWorkbook.Worksheets

WS.Activate

Cells.Select
Selection.EntireRow.Hidden = False
Selection.EntireColumn.Hidden = False
For Each X In ActiveSheet.UsedRange.Columns(1).Cells
If X.Value = "False" Then
X.EntireRow.Hidden = True
ActiveSheet.Range("A1").Select

End If

Next X

Next WS


Application.ScreenUpdating = True
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hello Klb1503,

You will need to use a conditional statement like IF Then or Select Case to test the current worksheet's name against a list of the worksheets to ignore.
 
Upvote 0
Perhaps.
Code:
Sub Hide_Columns_Containing_Value()
Dim WS As Worksheet
Dim X As Range
Dim I As Long

    Application.ScreenUpdating = False
    
    For I = 1 To ThisWorkbook.Sheets.Count - 5

        Set WS = ThisWorkbook.Sheets(I)
        
        With WS

            With .Cells
                .EntireRow.Hidden = False
                .EntireColumn.Hidden = False
            End With
            
            For Each X In .UsedRange.Columns(1).Cells
                If X.Value = "False" Then
                    X.EntireRow.Hidden = True
                End If
            Next X
            
        End With

    Next I

    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,873
Members
449,056
Latest member
ruhulaminappu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top