Question

Hiding and Unhiding worksheets based on Drop Down list

Asked by: sp70

Hello Experts,
I have a drop down with five items.  Each item in the drop down contains the first portion of the name of 5 different worksheets in the same book.

What I would like to do is the following:

When selecting the item from the drop down list (on a separate worksheet), the appropriate worksheet 'unhides', as well as hiding the currently open workbook.  Preferably making the switch to the other workbook without exposing 2 worksheets (granted it may be very quick).

So with worksheet 'Foobar Restaraunt' open (not hidden), I select 'Foobar2' from the drop down, worksheet 'Foobar Restaraunt' is then hidden, and 'Foobar2 Restaraunt' is unhidden.  I do NOT want focus set to the exposed workbook after the the drop down selection.

Wash, rinse, repeat.

Thank you.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-01-14 at 12:56:05ID24052476
Tags

drop down list

,

hide worksheet

,

unhide worksheet

,

Microsoft Excel 2007

Topic

Microsoft Excel Spreadsheet Software

Participating Experts
2
Points
500
Comments
21

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Get the sheet to Unhide in Excel
    Hello experts, In VB Editor I see three worksheets in my workbook, but only two visible as tabs. When I go Format -> Sheet -> to Unhide, the Unhide option is dimed, not available. Workbook and worksheets are Unprotected. What was that command in VBA, something...
  2. Unhiding Multiple Worksheets
    It is possible in Excel to hide several worksheets at the same time. How would I be able to unhide them at the same time? Thanks, jcdelgado
  3. Unhiding all sheets in workbook
    I have about 20-30 hidden sheets ( xlveryhidden ), which I need to unhide. Is there a way to unhide all tabs other then writing the following code for each tab. Sheets("Sunday").Visible = True Sheets("Monday").Visible = True Sheets("Tuesday").V...
  4. Option to Hide/Unhide Columns in a Protected Worksheet
    Is there an easy way to give a user the option to hide or unhide columns in a protected worksheet?
  5. Unhide worksheets listed in a range
    I have a workbook with numerous sheets and would like to hide the ones not in use. I would like to keep the first two visible and unhide the others as they are added to a list on the first worksheet. I can not get my code to function by referring to the range. Code so far ...
  6. unhide worksheet iwth a button
    I need to unhide a worksheet with a button while keeping the workbook protected.

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: saurabh726Posted on 2009-01-14 at 13:00:56ID: 23377439

Sp,

Can you please upload a sample file as it becomes easy to design a solution for you about what you are looking for...

Saurabh...

 

by: DreamboatPosted on 2009-01-14 at 13:18:50ID: 23377645

So, what you're saying is you'd need to have this dropdown as a (potential custom) toolbar (because it has to be available with every sheet...). So why not just record some macros that do what you want, then assign those macros to toolbar buttons?

Recording macros:
http://www.officearticles.com/excel/record_a_macro_in_microsoft_excel.htm

Launching macros:
http://www.officearticles.com/misc/methods_to_run_a_macro_in_microsoft_office_applications.htm

Hope it helps!

 

by: sp70Posted on 2009-01-14 at 13:30:56ID: 23377786

Sure.

The Drop Down in question is on the 'Score Sheet' Worksheet in cell D1.

Depending on what is selected in the drop down, I want to hide all other '...Average' worksheets, only exposing the appropriate worksheet based on what is selected in cell D1.

There are already subs in place for this worksheet .  I'm thinking that it would be appropriate to add this functionality to the 'Worksheet_SelectionChange' sub, but wasn't sure.

Thanks.

 

by: sp70Posted on 2009-01-14 at 13:32:38ID: 23377801

Hi Dreamboat,
I know about recording macros, but wasn't sure where to incorporate this functionality in my existing code.

See attached in previous post of this thread.

 

by: saurabh726Posted on 2009-01-14 at 13:50:11ID: 23378031

I cant open the workbook...as whenever i try to open it my excel crashes..can you please update the same again...

 

by: sp70Posted on 2009-01-14 at 14:02:46ID: 23378183

Which version of Excel are you using?

 

by: saurabh726Posted on 2009-01-14 at 14:03:25ID: 23378193

2003

 

by: sp70Posted on 2009-01-14 at 14:10:44ID: 23378288

strange.  your the first person to report this problem as I've had multiple people use this spreadsheet.  Now I'm concerned as to what's causing this.

 

by: saurabh726Posted on 2009-01-14 at 14:11:58ID: 23378304

Can be possible..that while uploading the file got corrupted so if you update again..it will be resolved..

 

by: sp70Posted on 2009-01-14 at 14:16:10ID: 23378362

If this attachment doesn't work again, please take a look at a different posting that had an attachment as well:

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_23810671.html

 

by: saurabh726Posted on 2009-01-14 at 14:43:37ID: 23378667

I was not still able to download the file..but i made this macro...just add this into the score sheet module..and it will do what you want...I have assumed you have used validation in D1 and the sheet names and the list in the validation is exactly the same...

Saurabh....

Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Me.Range("D1")) Is Nothing Then Exit Sub
    If Trim(Range("d1").Value) = "" Then Exit Sub
    Dim ws As Worksheet, ws1 As Worksheet, X As String
    Set ws = ActiveSheet
    X = Range("D1").Value
 
    For Each ws1 In ActiveWorkbook.Worksheets
        If ws1.Name = ws.Name Or ws1.Name = X Then
            ws1.Visible = xlSheetVisible
        Else
            ws1.Visible = xlSheetVeryHidden
        End If
    Next ws1
End Sub

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:

Select allOpen in new window

 

by: sp70Posted on 2009-01-14 at 16:38:24ID: 23379558

This is close.  Now everything but the scoresheet is getting hidden.

The drop down list items are not identical to the worksheet tab names.  Just the first portion is the same.  Each worksheet name is followed by ' Average'.

 

by: saurabh726Posted on 2009-01-14 at 16:40:48ID: 23379573

It should not hide the scoresheet as it wont hide the sheet where you apply this..and can you give me a couple of sample sheet names which has average to look at since i cant open your workbook...

 

by: sp70Posted on 2009-01-14 at 17:09:57ID: 23379708

Drop Down List:

   Bremerton
   City2
   City3
   ...

Sheet name:

  Bremerton Average
  City2 Average
  City3 Average
  ...

 

by: saurabh726Posted on 2009-01-14 at 17:18:46ID: 23379742

Okay use this...

Saurabh...

Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Me.Range("D1")) Is Nothing Then Exit Sub
    If Trim(Range("d1").Value) = "" Then Exit Sub
    Dim ws As Worksheet, ws1 As Worksheet, X As String
    Set ws = Sheets("Scoresheet")
    X = Range("D1").Value & " Average"
    
 
    For Each ws1 In ActiveWorkbook.Worksheets
        If ws1.Name = ws.Name Or ws1.Name = X Then
            ws1.Visible = xlSheetVisible
        Else
            ws1.Visible = xlSheetVeryHidden
        End If
    Next ws1
End Sub
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:

Select allOpen in new window

 

by: sp70Posted on 2009-01-14 at 18:26:06ID: 23380037

Curious about the reasoning for the usage of "xlSheetVeryHidden".  Using that prevents users from 'unhiding' any other sheets.  That's a neat trick though.

 

by: saurabh726Posted on 2009-01-14 at 18:36:48ID: 23380075

I used that because this will make the sheet go very hidden..so incase if there is a curious user who wants to look under format-->sheet-->unhide..he wont find it there..even when the worksheet is there in your workbook and hidden...

 

by: sp70Posted on 2009-01-14 at 22:01:53ID: 23380927

That's a very handy trick.  I can certainly use that on other sheets.

 

by: sp70Posted on 2009-01-15 at 15:19:13ID: 23388989

saurabh726,

I realize that I was not clear with my original request.

I need to hide all tabs ending with " Average" other than the one that is chosen from the drop down.

The reason behind this is because there are other tabs that need to be displayed.

So as an example, I need:

Dropdown:

  City1 (selected)

Worksheets:

  Worksheet1 (visible)
  Worksheet2 (visible)
  Worksheet3 (visible)
  City1 Average (visible)
  City2 Average (hidden)
  City3 Average (hidden)
  City4 Average (hidden)

I'm currently getting:

Dropdown:

  City1 (selected)

Worksheets:

  Worksheet1 (hidden)
  Worksheet2 (hidden)
  Worksheet3 (hidden)
  City1 Average (visible)
  City2 Average (hidden)
  City3 Average (hidden)
  City4 Average (hidden)


Right now, everything (including the scoresheet) is getting hidden except for the worksheet that's selected from the drop down.in the drop down.

I can email you the working copy I have if you let me know where to send it.

Shad

 

by: saurabh726Posted on 2009-01-15 at 15:28:54ID: 23389055

There you go use this..i assumed you want to show sheet scoresheet, sheet1,sheet2 and sheet3...

Saurabh...

Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Me.Range("D1")) Is Nothing Then Exit Sub
    If Trim(Range("d1").Value) = "" Then Exit Sub
    Dim ws As Worksheet, ws1 As Worksheet, X As String, ws2 As Worksheet, ws3 As Worksheet, ws4 As Worksheet
    
    Set ws = Sheets("Scoresheet")
    Set ws2 = Sheets("Sheet1")
    Set ws3 = Sheets("Sheet2")
    Set ws4 = Sheets("Sheet3")
    X = Range("D1").Value & " Average"
    
 
    For Each ws1 In ActiveWorkbook.Worksheets
        If ws1.Name = ws.Name And ws1.Name = X And ws1.Name = ws2.Name And ws1.Name = ws3.Name And ws1.Name = ws4.Name Then
            ws1.Visible = xlSheetVisible
        Else
            ws1.Visible = xlSheetVeryHidden
        End If
    Next ws1
End Sub

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:

Select allOpen in new window

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...