krunal123

Board Regular
Joined
Jun 26, 2020
Messages
177
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
1686720182646.png



'This macro will hide all the worksheet except the active sheet
Sub HideAllExceptActiveSheet()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> ActiveSheet.Name Then ws.Visible = xlSheetHidden
Next ws
End Sub

This code its working But We need 'This macro will Unhide all the worksheet except the active sheet

Pleased Help & Share VBA Code........
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Well, something like this would do the job:
VBA Code:
Sub UnHideAllExceptActiveSheet()
    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> ActiveSheet.Name Then ws.Visible = True
    Next ws
End Sub
 
Upvote 0
Since the active sheet must be visible to start with (& it doesn't hurt to re-set that visible status), it seems pointless to bother checking the names of the sheets.

VBA Code:
Sub UnHideAllSheets()
  Dim ws As Worksheet
 
  For Each ws In Worksheets
    ws.Visible = True
  Next ws
End Sub
 
Upvote 0
See if this workbook does what you want.

Worksheet_FollowHyperlink event for the DESKBOARD worksheet:

VBA Code:
Option Explicit

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)

    Dim wsLoop As Worksheet
   
    Dim sNavSheetName As String
   
    Dim sSheetName As String
   
    sNavSheetName = "DESKBOARD"
   
    sSheetName = Trim(Target.Name)
   
    If Not WorksheetExists(sSheetName) _
     Then
        MsgBox "Worksheet " & sSheetName & " does not exist.", vbInformation
        Exit Sub
    End If
   
    Worksheets(sSheetName).Visible = True
   
    Worksheets(sNavSheetName).Visible = True

    For Each wsLoop In Worksheets
       
        If wsLoop.Name <> sSheetName And wsLoop.Name <> sNavSheetName _
         Then
             wsLoop.Visible = xlSheetHidden
        End If
   
    Next wsLoop
   
End Sub

Code to check if a worksheet exists. Used so the event code above does not try to open a worksheet that does not exist.

VBA Code:
Option Explicit

Function WorksheetExists(psSheetName As String)
    
    Dim wsSheet As Worksheet
    
    WorksheetExists = False
    
    For Each wsSheet In Worksheets
        If psSheetName = wsSheet.Name Then WorksheetExists = True
        Exit Function
    Next wsSheet
    
End Function
 
Upvote 0
My apologies. That code does not work. I'll repost when I fix it.
 
Upvote 0
Try this version.

VBA Code:
Option Explicit

Function WorksheetExists(psSheetName As String) As Boolean
   
    Dim wsTest As Worksheet
   
    WorksheetExists = False
   
    For Each wsTest In ThisWorkbook.Worksheets
        If psSheetName = wsTest.Name _
         Then
            WorksheetExists = True
            Exit For
        End If
   
    Next wsTest
   
End Function
 
Upvote 0
Solution
Try this version.

VBA Code:
Option Explicit

Function WorksheetExists(psSheetName As String) As Boolean
   
    Dim wsTest As Worksheet
   
    WorksheetExists = False
   
    For Each wsTest In ThisWorkbook.Worksheets
        If psSheetName = wsTest.Name _
         Then
            WorksheetExists = True
            Exit For
        End If
   
    Next wsTest
   
End Function
 
Upvote 0
Peter_SS. I apologize for the redundancy. I'm not sure what I did to post the same thing twice. I did not mean to.

I believe that the corrected workbook that I posted does do what was requested. It is marked as a solution.
 
Upvote 0
Peter_SS. I apologize for the redundancy. I'm not sure what I did to post the same thing twice. I did not mean to.
Fair enough - no real problem. I just couldn't see any difference but thought there must have been something.

I believe that the corrected workbook that I posted does do what was requested. It is marked as a solution.
I can't argue with the last part of that though I am confused by it - for two reasons
  • When I first saw the thread post 2, which does something very different to yours, was marked as the solution. Some time later post 3, which also does something very different to yours, was marked as the solution. Now your is.
  • Both the thread title and the text & the image in post 1 all include ".. Unhide all the worksheets except .." whereas your code "Hides all the worksheets except .."
In the end of course it is up to the OP, though unfortunately we have not had any feedback from them apart from a number of changes to the marked solution.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,187
Members
452,616
Latest member
intern444

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