• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Hide, Delete and Sort Sheets With VBA Userform

You are here: Home / Excel VBA / Hide, Delete and Sort Sheets With VBA Userform
Hide, Delete, Sort Sheets with VBA in Excel
July 21, 2016 by Philip Treacy

You have a workbook with lots of sheets and you want to do things like hide sheets, delete some sheets or just sort them.

By using a very simple userform and some VBA we can do these things with a few clicks of our mouse.

The Form

The forms consist of one ListBox and four Command Buttons:

Form design

The List Box will display the list of sheets in the active workbook, and the buttons do exactly what they say.

Hiding and Unhiding Sheets

Rather than create a button to hide a sheet, I decided to make use of the _DblClick event. By using your mouse and double clicking on the name of a sheet, you hide it. Double click it again to unhide it.

Form design

Deleting Sheets

Click on a sheet name, then click the Delete button. You can select more than one sheet by holding down the CTRL key whilst clicking with your mouse.

Form design

Sorting Sheets

You can sort in ascending order (Sort A-Z) or descending order (Sort Z-A).

Form design

Extra Functionality

It's things like this make your life that bit easier and is exactly what VBA is built for.

This is a simple example of what you can do with a form and only scratches the surface of what is possible.

If you want to really see some cool stuff like :

  • Searching for worksheets and navigating to them.
  • Copying and renaming sheets.
  • Protecting and unprotecting sheets.
  • Moving, organizing, and coloring sheets.
  • Flipping back and forth between two sheets.
  • Jump to the first or last sheet.
  • Moving sheets up, down, first, or last.
  • See how many worksheets are in a workbook?
  • See how many hidden sheets there are.
  • Count how many sheets have a particular tab color.

Then you should check out the excellent Tab Hound which is made by Jon Acampora over at Excel Campus.

The Code

Enter your email address below to download the sample workbook.

By submitting your email address you agree that we can email you our Excel newsletter.
Please enter a valid email address.

If you want to look at my code and have a play around with it, you can download the workbook with the sample code.

Put the code (the form module and the code module) into your PERSONAL.XLSB so you can run it on any workbook.

Then you could add an icon to the QAT so you can run the code with a click of your mouse.

Hide, Delete, Sort Sheets with VBA in Excel

More Userforms Posts

Display All Matches from Search in Userform ListBox

Display All Matches from Search in Userform ListBox

Search a range for all partial and full matches of a string, and display matching records (entire rows) in a userform listbox. Sample code and userform.
dynamic data validation lists in userforms

Dynamic Data Validation Lists in Userforms

Data validation lists using the same source that are dynamically modified to prevent the same choice being made in each list.
Excel Calendar (Date Picker) to Use in Worksheets and Userforms

Multi-Language Excel Calendar (Date Picker) for Worksheets and Userforms

Easy to use, highly customizable and multi-language. This date picker is implemented as a userform that is simple to integrate into your workbook.
search for data with userform

Searching for Data With a User Form

Search a list of records (like a table) using a user form, and then populate the fields of the search form when the record is found.
add data to combo box drop down list in excel form

Add Data to Combo Box Drop Down List in Excel Form

If the values in your Excel Form's drop down list aren't sufficient, allow the user to add their own, and save the new value in the list to use again.
Excel forms, insert, update, delete data

Excel Forms – Insert, Update and Delete

Insert, update and delete data in an Excel table with a user form.
excel form data validation

Excel Form Data Validation

Thorough and effective Excel form data validation techniques. Clearly communicate errors to your users without annoying them.
excel date picker

Excel Date Picker

An Excel date picker (calendar) for all versions of Excel, both 32 and 64 bit. An easy to use VBA class, with examples to download in a workbook
excel userforms

Excel Forms

Learn how to create Excel forms for tasks like data entry. Use form controls to gather data, then enter this data into a table on your worksheet.
Excel Form Controls

Excel Form Controls

Add interactivity to your spreadsheets with user friendly form controls like option buttons, combo boxes, check boxes and scrollbars.

More Excel VBA Posts

Display All Matches from Search in Userform ListBox

Display All Matches from Search in Userform ListBox

Search a range for all partial and full matches of a string, and display matching records (entire rows) in a userform listbox. Sample code and userform.
animating excel charts

Animating Excel Charts

Use animation correctly to enhance the story your data is telling. Don't animate your chart just for some eye candy. Sample code and workbook to download.
dynamic data validation lists in userforms

Dynamic Data Validation Lists in Userforms

Data validation lists using the same source that are dynamically modified to prevent the same choice being made in each list.
show report filter pages for power pivot pivottables

Show Report Filter Pages for Power Pivot PivotTables

PivotTables created from Power Pivot can't use the 'Show Report Filter Pages' option. But this piece of VBA allows you to do just that.
charting real time data in excel

Charting Real Time Data in Excel

Receive data in real time and chart the data as it arrives. Can be used to chart things like stock prices or sensor readings. Sample code and workbook
select multiple items from drop down data validation list

Select Multiple Items from Drop Down (Data Validation) List

Choose multiple items from a data validation (drop down) list and store them all in the same cell. Sample workbook with working VBA.
Excel Calendar (Date Picker) to Use in Worksheets and Userforms

Multi-Language Excel Calendar (Date Picker) for Worksheets and Userforms

Easy to use, highly customizable and multi-language. This date picker is implemented as a userform that is simple to integrate into your workbook.
automating and emailing pivot table reports

Automating and Emailing Pivot Table Reports

Automate the creation and distribution of pivot table reports with some VBA. Send reports to multiple email recipients using Outlook.
search for data with userform

Searching for Data With a User Form

Search a list of records (like a table) using a user form, and then populate the fields of the search form when the record is found.
Checking values in range objects with vba

Checking Values in Range Objects With VBA

Use built in tools or your own code to examine the values contained within Range objects in VBA. Sample code to download.


Category: Excel VBATag: Userforms
Previous Post:Excel ClipboardExcel Clipboard
Next Post:Moving VBA Code and Forms Into PERSONAL.XLSBMoving VBA Code and Forms Into PERSONAL.XLSB

Reader Interactions

Comments

  1. Arnaldo

    October 3, 2018 at 3:31 am

    Hi guys
    Many thanks for the code and form. Extremely useful.
    However, could you please adivse how I could change the code (or add) so I could be able to hide some worksheets so they wouldn’t show on the list? I’ve tried it using the Case Function but wasn’t very successful.
    Thank you

    Reply
    • Philip Treacy

      October 3, 2018 at 5:36 pm

      Hi Arnaldo,

      If you change the sheet visibility so that it is xlSheetVeryHidden (in the VBA editor) then you can use this modified Sub to only list sheets that are not Very Hidden

      Sub PopulateList()
      
          Dim counter As Long
          Dim HiddenPrefix As String
          
          SheetList.Clear
          
          For counter = 1 To Sheets.count
              
              If Sheets(counter).Visible <> xlSheetVeryHidden Then
              
              If Sheets(counter).Visible = False Then
              
                  HiddenPrefix = "H"
              
              Else
                      
                  HiddenPrefix = ""
              
              End If
              
              SheetList.AddItem HiddenPrefix & vbTab & Sheets(counter).Name
              End If
          
          Next counter
      
      End Sub
      
      Reply
  2. Stuart Thompson

    July 19, 2017 at 7:36 am

    Hi
    This code is fantastic for doing exactly what I wanted.

    I did however modify this slightly so I can select the sheets for hiding and unhiding (the same ways as deleting) in addition to the double click option.

    Also added a Yes/No check when deleting sheets with a message are you sure?

    Thanks for sharing this code

    Reply
    • Philip Treacy

      July 19, 2017 at 8:38 am

      Thanks Stuart, glad you found it useful

      Reply
  3. Ben M

    July 29, 2016 at 12:43 am

    Phil,

    Thanks for putting this tool together. It makes things much easier when managing a large workbook with several hidden sheets. I have added it to my Personal.xlsb with a QAT icon and have already used it quite often.

    After playing around with it some, I added a feature that may be of interest to you or others – the ability to see/make “Very Hidden” sheets. As I’m sure you’re aware, there are three Visible properties of sheets. Most people use only the Hidden or Visible properties, but the Very Hidden property will hide a sheet in such a way that it doesn’t show up when right-clicking to unhide sheets. This can be handy when trying to prevent users from unhiding a critical sheet and making changes you didn’t intend.

    The tweak I made to the PopulateList code was to use a Select Case statement on the Sheets.Visible property where Case 0 is Hidden (so returns “H”), Case 2 is Very Hidden (so returns “V”), and Case Else assumes Visible (so returns “”). I then copied the Delete button code and adjusted it to make a sheet VeryHidden so that you can select any sheet and click the button to make it Very Hidden.

    Thanks again for this post!

    Reply
    • Philip Treacy

      July 29, 2016 at 8:29 am

      Excellent work Ben. It’s great to hear what you have done and this is exactly why I do this. So people like yourself can take my code and tweak/enhance it to suit their own needs and add extra bits of functionality.

      Good job.

      Phil

      Reply
    • Justin

      November 29, 2018 at 3:32 am

      Ben,

      Would you be so kind to share this modified code by any chance?

      Thanks,
      Justin

      Reply
  4. Ron S

    July 22, 2016 at 2:31 am

    Excellent tip and and tool. A couple of tweaks I’d like to see.

    Column headings in the form: Hidden, Sheet name, Description(?)

    I would like to see the option to add a hidden tab with longer descriptions / comments about the sheet. If a predefined tab name for the comments is found, then a lookup is performed on the tab names to find descriptions.

    Please add a link to tutorial on how to copy this userform and all of it’s associated code to the PERSONAL.XLSB (assuming they don’t have one, like me. I saw your tutorial on creating an PERSONAL, but I don’t see how to move the userform to it. Is that an export, import process?

    PS: add a note to this article reminding people that they could also create a button on their QAT to trigger this form, rather than the button you use in your example. This is handier when sharing the code with other forms where there may not be an appropriate place to put the button. After downloading your file and adding the macro button to the QAT I was able to use the form in other spreadsheets (of course it opens your example sheet in the process, oops).

    I presume, adding the macro from the PERSONAL.XLSB would not launch the sheet?

    Reply
    • Philip Treacy

      July 25, 2016 at 9:13 am

      Hi Ron,

      All good suggestions. I didn’t include headings because it seemed clear to be what the sheet name was, but you can of course alter the form and quickly add a couple of labels in the right place.

      A hidden sheet with descriptions for each sheet would also be a feature, but would complicate the coding somewhat.

      I will write a separate tutorial on moving code into the PERSONAL.XLSB. You can export/import the code and form modules, or just click on the module in my workbook and drag it into PERSONAL.XLSB, as shown in the animated image towards the bottom of this post Excel progress bar in VBA

      Yes, adding an icon on the QAT is the way to go, and I added a link to my article on doing just that. I overlooked that when I wrote the blog!

      And yes, once the code and form are in PERSONAL.XLSB, running the code won’t open my workbook.

      Thanks

      Phil

      Reply
  5. Jon Acampora

    July 22, 2016 at 2:13 am

    Great utility Phil. It’s amazing how we can greatly enhance Excel’s functionality with a little bit of code. That’s why I love it. 🙂

    I appreciate you mentioning Tab Hound as well. I use it everyday to search for and jump to sheets in the workbook quickly. It’s like Google Search for worksheets. 🙂

    Reply
    • Philip Treacy

      July 22, 2016 at 12:23 pm

      Hi John,

      No worries, Tab Hound is excellent.

      Cheers

      Phil

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Current ye@r *

Leave this field empty

Sidebar

More results...

Featured Content

  • 10 Common Excel Mistakes to Avoid
  • Top Excel Functions for Data Analysts
  • Secrets to Building Excel Dashboards in Less Than 15 Minutes
  • Pro Excel Formula Writing Tips
  • Hidden Excel Double-Click Shortcuts
  • Top 10 Intermediate Excel Functions
  • 5 Pro Excel Dashboard Design Tips
  • 5 Excel SUM Function Tricks
  • 239 Excel Keyboard Shortcuts

100 Excel Tips and Tricks eBook

Download Free Tips & Tricks

Subscribe to Our Newsletter

Receive weekly tutorials on Excel, Power Query, Power Pivot, Power BI and More.

We respect your email privacy

Guides and Resources

  • Excel Keyboard Shortcuts
  • Excel Functions
  • Excel Formulas
  • Excel Custom Number Formatting
  • ALT Codes
  • Pivot Tables
  • VLOOKUP
  • VBA
  • Excel Userforms
  • Free Downloads

239 Excel Keyboard Shortcuts

Download Free PDF

Free Webinars

Excel Dashboards Webinar

Watch our free webinars and learn to create Interactive Dashboard Reports in Excel or Power BI

Click Here to Watch Now

mynda treacy microsoft mvpHi, I'm Mynda Treacy and I run MOTH with my husband, Phil. Through our blog, webinars, YouTube channel and courses we hope we can help you learn Excel, Power Pivot and DAX, Power Query, Power BI, and Excel Dashboards.

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk – For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.