Hide selected sheets only

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello guys,
I have 6 sheets in the workbook. I want to hide sheet "Data" and sheet "Steps". The other 3 sheets are working sheets say X, Y and Z sheets. With the help of a code I want to hide X, Y and Z sheets only at the end of the code. How do I edit this code not to hide the sheet "Data" and sheet "Steps"? With this code I am able to hide one sheet only. The X sheet gets hidden when the code ends.

Rich (BB code):
Option Explicit

Sub HideSheets()
    Dim ws As Worksheet
    For Each ws In Sheets(Array("X"))
         ws.Visible = xlSheetVeryHidden
    Next ws
End Sub
   
Sub UnHideSheets()
Dim ws As Worksheet
For Each ws In Worksheets: ws.Visible = xlSheetVisible

Next ws
End Sub





	
	
	
	
	
	


VBA Code:
 
Last edited:

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Sorry, I want to hide the shetts X, Y and Z and not as mentioned above
 
Upvote 0
Try:

VBA Code:
Sub HideSheets()
Dim oneIndex As Variant
'Hide sheets

Application.ScreenUpdating = False

For Each oneIndex In Array("X", "Y", "Z")
    Sheets(oneIndex).Visible = xlSheetHidden
Next oneIndex

Application.ScreenUpdating = True

End Sub
 
Upvote 0
Solution
Try:

VBA Code:
Sub HideSheets()
Dim oneIndex As Variant
'Hide sheets

Application.ScreenUpdating = False

For Each oneIndex In Array("X", "Y", "Z")
    Sheets(oneIndex).Visible = xlSheetHidden
Next oneIndex

Application.ScreenUpdating = True

End Sub
Thank you Logit.?
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,539
Members
449,088
Latest member
RandomExceller01

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