Hide Sheets in workbook (Code enclosed)

vidplaylist

Board Regular
Joined
Aug 3, 2011
Messages
78
I want that Sheets name given in column C get hide in workbook if i write No in Column E. Similarly display Sheet in workbook if i write Yes.

Note: i have to apply this formula on this range only.

Somewhere i am doing mistake so, please help.

Sub DisplaySheetHide()

Dim Cell As Range

For Each Cell In Range("E1:E17")

If Cell.Value = "No" Then

ActiveCell.Offset(0, -2).Select

Sheets(Cell.Value).Visible = xlSheetVeryHidden

ElseIf Cell.Value = "Yes" Then

ActiveCell.Offset(0, -2).Select

Sheets(Cell.Value).Visible = xlSheetVisible

End If


Next Cell

End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try

Code:
Sub DisplaySheetHide()
Dim Cell As Range
For Each Cell In Range("E1:E17")
    If Cell.Value = "No" Then
        Sheets(Cell.Offset(, -2).Value).Visible = xlSheetVeryHidden
    ElseIf Cell.Value = "Yes" Then
        Sheets(Cell.Offset(, -2).Value).Visible = xlSheetVisible
    End If
Next Cell
End Sub
 
Upvote 0
1-Oh no, I am getting " Subscript out of range" Run-time error '9':
2- I am wondering if i put "yes" and sheet is already visible(not hidden) then what will happen. How i can ignore this statement in code if sheet is already visible and i put "Yes" in column E
 
Upvote 0
That error means that one of the sheets in your range doesn't exist. Maybe you have misspelt it or there are leading or trailing spaces.
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,451
Members
452,915
Latest member
hannnahheileen

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