VBA Tabs Unhide to Hide ?

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,113
Office Version
  1. 365
Platform
  1. Windows
Hi All;

I am using Excel 2013 and I can of course record a macro to unhide all tabs in a worksheet (& also to do its reverse in a separate macro).

My ? is; is there a written code to expidite this process as opposed to recording one?

Many thanks in advance.

R/

-Pin:confused:
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I can of course record a macro to unhide all tabs in a worksheet (& also to do its reverse in a separate macro).
Not quite the reverse as a workbook must always have at least one visible worksheet.
Try these though.

To make all visible
Code:
Sub Unhide_All()
  Dim ws As Worksheet
  
  For Each ws In Sheets
    ws.Visible = xlSheetVisible
  Next ws
End Sub


To hide all except the left hand sheet
Code:
Sub HideAll_ExceptOne_v1()
  Dim i As Long
  
  Sheets(1).Visible = xlSheetVisible
  For i = 2 To Sheets.Count
    Sheets(i).Visible = xlSheetHidden
  Next i
End Sub

To hide all except one with a specific name
Code:
Sub HideAll_ExceptOne_v2()
  Dim ws As Worksheet
  
  Const KeepVisible As String = "Sheet2"
  
  Sheets(KeepVisible).Visible = xlSheetVisible
  For Each ws In Sheets
    ws.Visible = ws.Name = KeepVisible
  Next ws
End Sub
 
Upvote 0
Peter:

I don't understand how this part of your script works. I see it works but don't understand what "xl" means.
Code:
ws.Visible = xlSheetVisible
Trying to read and understand code.
 
Upvote 0
Peter:

I don't understand how this part of your script works. I see it works but don't understand what "xl" means.
Code:
ws.Visible = xlSheetVisible
Trying to read and understand code.
The 'xl' is just part of the syntax. If you look at the vba Help you will find there are three states of worksheet visibility:

xlSheetVisible, xlSheetHidden, xlSheetVeryHidden

These can be substituted with, respectively, the following values -1, 0, 2

On this occasion I chose to use the full name as it is more descriptive of what it does.
 
Upvote 0
Hi Peter,

You are right, one sheet has to be visible, sorry on my verbiage. Let me give it a go.

Thanks again :)
-Pin
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,561
Members
449,038
Latest member
Guest1337

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