Hide tab if not hidden - unhide if tab is hidden and go to

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,340
Office Version
  1. 365
Platform
  1. Windows
I have code that is triggured by a button that will hide or unhide a tab. What I need is if the tab is hidden when the button is click it not only unhides but it also activates that sheet/tab

Code:
Sub SeeBOE()
With Sheet5
   .Visible = Not .Visible
End With

End Sub

Thank you for your help
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
How about
VBA Code:
Sub SeeBOE()
With Sheet5
   If .Visible Then
      .Visible = xlSheetHidden
   Else
      .Visible = xlSheetVisible
      .Activate
   End If
End With

End Sub
 
Upvote 0
Hi,
try this update to your code

VBA Code:
Sub SeeBOE()
    With Sheet5
       .Visible = Not .Visible
       If .Visible Then .Activate
    End With
End Sub

Dave
 
Upvote 0
Just add one line:
VBA Code:
Sub SeeBOE()

With Sheet5
   .Visible = Not .Visible
End With

If Sheet5.Visible = True Then Sheet5.Activate

End Sub
 
Upvote 0
Solution
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,667
Messages
6,120,815
Members
448,990
Latest member
rohitsomani

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