Solved

Making a Chart "Visible"

Posted on 2012-03-30
10
420 Views
Last Modified: 2012-06-27
EE Pros.;

I have a macro that when fired, it exposes a set of Sheets and two Charts.  I have no problem with the Sheets or Charts showing up

Here is the code;

Private Sub Worksheet_Change(ByVal Target As Range)
       Application.ScreenUpdating = False
  Select Case Target.Address
      Case "$N$17"
    If [n17].Value = "" Then Exit Sub
        On Error Resume Next
       
Sheets("FUN_Assessment").Visible = xlSheetHidden: Sheets("GWS_Process_Questions").Visible = xlSheetHidden: Sheets("Strategic_Priorities").Visible = xlSheetHidden
       
Sheets("GWS Questionaire").Visible = xlSheetHidden: Sheets("Heatmaps").Visible = xlSheetHidden: Sheets("Capability Gaps").Visible = xlSheetHidden: Sheets("Maturity by Category").Visible = xlSheetHidden: Sheets("GWS_Process_Survey_Questions").Visible = xlSheetHidden: Sheets("Radar_Chart").Visable = xlSheetHidden
       
Sheets("Maturity Model").Visible = xlSheetHidden: Sheets("MaturityChart").Visible = xlSheetHidden: Sheets("Spider Chart").Visible = xlSheetHidden
       
Sheets("CA_Questionaire").Visible = xlSheetHidden: Sheets("CA_Capability_Heatmap").Visible = xlSheetHidden: Sheets("CA_Prioritization").Visible = xlSheetHidden
       
Sheets("CA_Priority_Heatmap").Visible = xlSheetHidden: Sheets("CA_Instructions").Visible = xlSheetHidden: Sheets("CA_Detailed_Results").Visible = xlSheetHidden
       
Charts("CA_Summary_Scores").Visible = xlSheetHidden: Charts("CA_Detailed_Results").Visible = xlSheetHidden
       
Sheets("GWS_Process_Survey_Questions").Visible = xlSheetHidden: Sheets("GWS_Survey").Visible = xlSheetHidden
       
Sheets("Radar_Chart").Visible = xlSheetHidden
       
Select Case Sheets("Splash").Range("N17").Value
            Case Is = Range("$N$17").Value
               
Sheets("CA_Questionaire").Visible = xlSheetVisible: Sheets("CA_Prioritization").Visible = xlSheetVisible: Sheets("CA_Priority_Heatmap").Visible = xlSheetVisible: Sheets("Maturity Model").Visible = xlSheetVisible: Sheets("Radar Chart").Visible = xlSheetVisible: Sheets("100%Chart").Visible = xlSheetVisible: Sheets("Priorities").Visible = xlSheetVisible: Charts("CA_Detailed_Results").Visible = xlSheetVisible: Charts("CA_Summary_Scores").Visible = xlSheetVisible
           
        End Select
        On Error GoTo 0
    Application.ScreenUpdating = True
    End Select
 
    If Target.Address = "$N$17" Then
    Sheet2.Unprotect Password:="jam"
        Worksheets("Question_DB").Range(Replace(Target.Value, " ", "_")).Copy Worksheets("CA_Questionaire").Range("A2")
        Application.GoTo Worksheets("CA_Questionaire").Range("A2")
    End If

    End Sub



What I have a problem with is when I go to hide all of the sheets and 2 charts.  The Charts do not go hidden.

I think I'm doing something wrong with the way I have the Charts identified in the line:

Charts("CA_Summary_Scores").Visible = xlSheetHidden: Charts("CA_Detailed_Results").Visible = xlSheetHidden

Thank you in advance,


B.
0
Comment
Question by:Bright01
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 17

Expert Comment

by:andrewssd3
ID: 37789246
You give a lot of code here, but not the context in which you try to hide the sheets.  They might fail to hide for various reasons - do you have an On Error Resume Next in effect that hides some error?  Also bear in mind that you cannot hide ALL worksheets (including charts) in a workbook.

Perhaps you could post the code that contains the Hide process - use the code style in the posting window as it makes it easier to read.
0
 

Author Comment

by:Bright01
ID: 37789558
Andrewssd3,

Thanks for the response;

1.) The "On Error Resume Next" is in the code. Take a look.
2.) All worksheets are not hidden.  One sheet called "Splash" is not hidden and is the only tab that should be visible.....and is.
3.) When I added "Charts" it worked to show the Charts, but when I tried to "hide" them, they all hid except the two charts.

An easier way to answer this question is, how do you identify "Charts" vs. "Sheets"?

Showing the Charts I use:  Charts("CA_Detailed_Results").Visible = xlSheetVisible: Charts("CA_Summary_Scores").Visible = xlSheetVisible

The Hiding Charts I use:  Charts("CA_Summary_Scores").Visible = xlSheetHidden: Charts("CA_Detailed_Results").Visible = xlSheetHidden

The problem is, when I fire the macro by entering a value in "N17" I get all the right tabs, including the Charts.  But when I clear them, all tabs are hidden except the Charts.

Make sense?

B.
0
 
LVL 41

Expert Comment

by:dlmille
ID: 37789927
Not for points, but suggest you change this snippet of code:
Sheets("CA_Questionaire").Visible = xlSheetVisible: Sheets("CA_Prioritization").Visible = xlSheetVisible: Sheets("CA_Priority_Heatmap").Visible = xlSheetVisible: Sheets("Maturity Model").Visible = xlSheetVisible: Sheets("Radar Chart").Visible = xlSheetVisible: Sheets("100%Chart").Visible = xlSheetVisible: Sheets("Priorities").Visible = xlSheetVisible: Charts("CA_Detailed_Results").Visible = xlSheetVisible: Charts("CA_Summary_Scores").Visible = xlSheetVisible

Open in new window


to this:
Dim shtVisible As String

    shtVisible = "CA_Questionaire,CA_Prioritization,CA_Priority_Heatmap,Maturity Model,Radar Chart,100%Chart,Priorities," & _
                 "CA_Detailed_Results,CA_Summary_Scores"

    Sheets(Split(shtVisible, ",")).Visible = xlSheetVisible

Open in new window


you can use the same approach for those sheets you want to hide.

pushing multiple lines of code on one line is not a good practice as its hard to read and debug.

This is one case where more is better - indenting, blank lines separating thoughts, etc., help create better, easier to read and debug apps.

Cheers,

Dave
0
 
LVL 17

Assisted Solution

by:andrewssd3
andrewssd3 earned 250 total points
ID: 37790167
IT's difficult to see why this should not work.  You can hide Charts in this way - it works in a test on my Excel 2010.  I would comment out the On Error Resume next and rerun to see if an error is occurring.  Alternatively you could post your whole workbook - it's difficult for me to set up a test without a workbook that has all the relevant sheets.

On your question about Sheets and Charts, the Sheets collection contains normal worksheets, charts and Macro sheets, so you should be able to refer to your chart sheets with Sheets("CA_Summary_Scores") as well as Charts("CA_Summary_Scores") .  The Worksheets collection contains only normal worksheets, and the Charts collection contains only Chart sheets.  However, what you're doing should be OK.

As usual I totally agree with Dave - your code would be much clearer if it was indented and had just one statement per line - it's much easier to see what's going on then.

Stuart
0
 

Author Comment

by:Bright01
ID: 37790848
Andrewssd3 and Dave,

I've cleaned up the code and here's the story.  On the "Splash" Screen in cell N17, I have a validation box that selects from a set of templates.  When a selection is made, the Private Sub Worksheet_Change(ByVal Target As Range) Macro should display the Tabs that are listed as "visible". It doesn't matter which Template is selected, the Tabs that become visable should appear.  For some reason, by the code below, when I make a selection in N17,  I do not get any change to the WB (i.e. no new Tabs visable). I believe the problem may be in how I've declared N17 value............. or case...............


Private Sub Worksheet_Change(ByVal Target As Range)
       Application.ScreenUpdating = False
  Select Case Target.Address
      Case Is = "$N$17"
    If [n17].Value = "" Then Exit Sub
        On Error Resume Next
               
        Dim shtVisible As String
       
        Select Case Sheets("Splash").Range("N17").Value
            Case Is = Range("$N$17").Value
           
            shtVisible = "CA_Questionaire,CA_Prioritization,CA_Priority_Heatmap,Maturity Model,Radar Chart,100%Chart,Priorities," & _
                 "CA_Detailed_Results,CA_Summary_Scores"

            Sheets(Split(shtVisible, ",")).Visible = xlSheetVisible

        End Select
        On Error GoTo 0
    Application.ScreenUpdating = True
    End Select
 
    If Target.Address = "$N$17" Then
    Sheet2.Unprotect Password:="pass"
        Worksheets("Question_DB").Range(Replace(Target.Value, " ", "_")).Copy Worksheets("CA_Questionaire").Range("A2")
        Application.GoTo Worksheets("CA_Questionaire").Range("A2")
    End If

    End Sub
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 41

Accepted Solution

by:
dlmille earned 250 total points
ID: 37791241
I assume that this worksheet_change code is on your Splash sheet, so we don't need to directly reference that sheet.  I left your case in as if you were going to do different things based on what's selected at N17, otherwise the case is not necessary.

On the last if statement, we've already ascertained that the change was made at N17, so that IF is not needed.

Try this:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim shtVisible As String

    If Target.Count > 1 Or Target.Value = vbNullString Then Exit Sub

    If Not Intersect(Target, Range("N17")) Is Nothing Then    'this detects that a change was made at the identified range
        Application.ScreenUpdating = False

        shtVisible = "CA_Questionaire,CA_Prioritization,CA_Priority_Heatmap,Maturity Model,Radar Chart,100%Chart,Priorities," & _
                     "CA_Detailed_Results,CA_Summary_Scores"
                     
        Select Case Range("N17").Value
        
            Case Range("N17").Value:
    
                On Error Resume Next
                Sheets(Split(shtVisible, ",")).Visible = xlSheetVisible
                On Error GoTo 0
        
            Case Else:
            
        End Select
        
        Application.ScreenUpdating = True

        Sheet2.Unprotect Password:="pass"
        Worksheets("Question_DB").Range(Replace(Target.Value, " ", "_")).Copy Worksheets("CA_Questionaire").Range("A2")
        
        Application.GoTo Worksheets("CA_Questionaire").Range("A2")
    End If

End Sub

Open in new window


Dave
0
 
LVL 41

Expert Comment

by:dlmille
ID: 37791248
Bright, when you have problems like this, its time to try debugging.  Select line 6 then hit F9, then toggle over and make a change, then it should break at line 6 and you can step through the code with F8 to see where the bouncing YELLOW line telling you where your code is about to run.  You can display the immediate window with VIEW->IMMEDIATE WINDOW if its not already displayed in your VBA editor.  You can then type things like:

debug.print Range("N17").value

or other commands to determine what the state of variables are, test sheet values, etc.

Cheers,

Dave
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 37795639
Idle curiosity:
        Select Case Range("N17").Value
        
            Case Range("N17").Value:

Open in new window


Why? (and why a colon at the end?)
0
 

Author Closing Comment

by:Bright01
ID: 37827348
Thank you guys!  Got it to work.  And Dave, not sure why I have a : at the end..............

B.
0
 
LVL 41

Expert Comment

by:dlmille
ID: 37828265
I must have missed rorya's post.  The colon is probably just a carryover from some other language.

I was just correcting the case statement's syntax as I assumed that Bright would be looking at different values at some point in the future.  IT may have been that he wanted to look at Range("N17")'s value and based on results hide certain sheets. The way its currently written of course the case statement is not required:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim shtVisible As String

    If Target.Count > 1 Or Target.Value = vbNullString Then Exit Sub

    If Not Intersect(Target, Range("N17")) Is Nothing Then    'this detects that a change was made at the identified range
        Application.ScreenUpdating = False

        shtVisible = "CA_Questionaire,CA_Prioritization,CA_Priority_Heatmap,Maturity Model,Radar Chart,100%Chart,Priorities," & _
                     "CA_Detailed_Results,CA_Summary_Scores"

        On Error Resume Next
        Sheets(Split(shtVisible, ",")).Visible = xlSheetVisible
        On Error GoTo 0
        
        Application.ScreenUpdating = True

        Sheet2.Unprotect Password:="pass"
        Worksheets("Question_DB").Range(Replace(Target.Value, " ", "_")).Copy Worksheets("CA_Questionaire").Range("A2")
        
        Application.GoTo Worksheets("CA_Questionaire").Range("A2")
    End If

End Sub

Open in new window


Alternatively, if Range("N17") has different values and you (Bright) want to act differently, you can use IF then else or a case statement like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim shtVisible As String

    If Target.Count > 1 Or Target.Value = vbNullString Then Exit Sub

    If Not Intersect(Target, Range("N17")) Is Nothing Then    'this detects that a change was made at the identified range
        Application.ScreenUpdating = False

        shtVisible = "CA_Questionaire,CA_Prioritization,CA_Priority_Heatmap,Maturity Model,Radar Chart,100%Chart,Priorities," & _
                     "CA_Detailed_Results,CA_Summary_Scores"
                     
        Select Case Range("N17").Value
        
            Case "ViewAll":
    
                On Error Resume Next
                Sheets(Split(shtVisible, ",")).Visible = xlSheetVisible
                On Error GoTo 0
        
            Case "ViewOne":
   
                Sheets("TheOneSheet").visible = xlSheetVisible
            Case Else:
            
        End Select
        
        Application.ScreenUpdating = True

        Sheet2.Unprotect Password:="pass"
        Worksheets("Question_DB").Range(Replace(Target.Value, " ", "_")).Copy Worksheets("CA_Questionaire").Range("A2")
        
        Application.GoTo Worksheets("CA_Questionaire").Range("A2")
    End If

End Sub

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now