Hiding Tabs using vba button

ReeceC952

New Member
Joined
May 11, 2016
Messages
10
Hi,

I have a spreadsheet with lots of tabs along the bottom. I have a homepage and I want to have a button that when you press it, you get a list of all the current tabs, and when you click one it will hide that tab.

Is there a way to do this using vba/macros?

Any help will be much appreciated,

ReeceC952
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
o possible way it to select a userform wth a listbox and commandbutton . create a text document with all the sheet names and save it down somewhere. then assign the below to the userform.

Code:
 Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
For lngCount = 0 To ListBox1.ListCount - 1
    If ListBox1.Selected(lngCount) = True Then
        strfilter = ListBox1.List(lngCount)
         
        End If
    Next
     
    Unload Me
  
lbl_Exit:
  Exit Sub
End Sub
 
Private Sub OK_Click()
For lngCount = 0 To ListBox1.ListCount - 1
    If ListBox1.Selected(lngCount) = True Then
        strfilter = ListBox1.List(lngCount)
         
        End If
    Next
     
    Unload Me
  
lbl_Exit:
  Exit Sub
End Sub




Private Sub UserForm_Initialize()
  Dim fn As String, ff As Integer, txt As String
    fn = "C:\Users\Subject.txt" '< --- .txt file path
    txt = Space(FileLen(fn))
    ff = FreeFile
    Open fn For Binary As #ff
    Get #ff, , txt
    Close #ff
  
 Dim myArray() As String
  'Use Split function to return a zero based one dimensional array.
  myArray = Split(txt, vbCrLf)
  'Use .List method to populate listbox.
  ListBox1.List = myArray
lbl_Exit:
  Exit Sub
  
End Sub

then add the below in a modle and run

Code:
Option Explicit
Public strfilter As String
Sub hide_sheets()
UserForm1.Show
Sheets(strfilter).Visible = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,126
Messages
6,129,021
Members
449,480
Latest member
yesitisasport

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