Solved

Simple Addition to Existing Macro

Posted on 2014-04-20
2
150 Views
Last Modified: 2014-04-25
EE Pros,

I have a nice little Macro that watches for a seletion from a list that when it is selected, it automatically displays the appropriate Tab.  There are actually 2 selections (N22 and N23 are the cells that change).  And when the cells are cleared, the Tab goes away.  It works.  However, now what I want is that when I select a particular list variable (
in N23), I want to display several tabs that are hidden... not just the one selected from the list.  How do I enter a line of code that adds the other Hidden Tabs and how do they vanish if the cell (N23) is blank?

Thank you in advance.


Private Sub Worksheet_Change(ByVal Target As Range)
    Dim ws As Worksheet
    Dim TabToHide As Variant
    If Target.Address = Range("N22").Address Then
        On Error Resume Next
        If Target.Value = "" Then

            For Each ws In ThisWorkbook.Worksheets
                TabToHide = Application.Match(ws.Name, Range("Tablist"), 0)
                If IsNumeric(TabToHide) Then
                    Sheets(ws.Name).Visible = False
                   
                    Sheet20.Visible = xlSheetVisible
                    Sheet20.Activate
                End If
            Next ws


        End If
        Sheets(Target.Value).Visible = True
        On Error GoTo 0
    End If

    If Target.Address = Range("N23").Address Then
        On Error Resume Next
        If Target.Value = "" Then

            For Each ws In ThisWorkbook.Worksheets
                TabToHide = Application.Match(ws.Name, Range("Typelist"), 0)
                If IsNumeric(TabToHide) Then
                    Sheets(ws.Name).Visible = False
                   
                    Sheet20.Visible = xlSheetVisible
                    Sheet20.Activate
                End If
            Next ws

        End If
        Sheets(Target.Value).Visible = True
        On Error GoTo 0
    End If
End Sub
0
Comment
Question by:Bright01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
Peter Kwan earned 500 total points
ID: 40011971
You may update as this:

    If Target.Address = Range("N23").Address Then
        On Error Resume Next
        If Target.Value = "" Then

            For Each ws In ThisWorkbook.Worksheets
                TabToHide = Application.Match(ws.Name, Range("Typelist"), 0)
                If IsNumeric(TabToHide) Then
                    Sheets(ws.Name).Visible = False
                   
                    Sheet20.Visible = xlSheetVisible
                    Sheet20.Activate
                End If
            Next ws
        Else
            For Each ws In ThisWorkbook.Worksheets
                If Sheets(ws.Name).Visible = False And ws.Name <> Target.Value Then
                  Sheets(ws.Name).Visible = True
                End If
            Next ws
        End If
        Sheets(Target.Value).Visible = True
        On Error GoTo 0
    End If

Open in new window

0
 

Author Closing Comment

by:Bright01
ID: 40022732
Pkwan,  Thank you!  Works great.  Sorry for the delay.......

B.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question