Hide Chart with Cell Change

VBAMePlease

Board Regular
Joined
Jun 19, 2017
Messages
59
Current Code:

Code:
Sub Chart_Toggle()

If Worksheets("Inputs").Range("F74").Value = 1 Then
    
    Worksheets("Structuring").ChartObjects("Chart 3").Visible = False


ElseIf Worksheets("Inputs").Range("F74").Value = 0 Then
    
    Worksheets("Structuring").ChartObjects("Chart 3").Visible = True


End If


End Sub

Obviously, I'd like this to run everytime F74 on "Inputs" is changed from a 1 to a 0 or vice-versa.

Thanks.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
You can use the Worksheet_Change event. Right-click the sheet tab for your Inputs sheet, select View Code, and copy/paste the following code into the code module for the sheet...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address <> "$F$74" Then Exit Sub
    Application.EnableEvents = False
    If Target.Value = 1 Then
        Worksheets("Structuring").ChartObjects("Chart 3").Visible = False
    ElseIf Target.Value = 0 Then
        Worksheets("Structuring").ChartObjects("Chart 3").Visible = True
    End If
    Application.EnableEvents = True
End Sub

Hope this helps!
 
Last edited:
Upvote 0
@Domenic Huge help - I couldn't use online resources to trigger the binary switch. Is there anyway to add-in an AND argument so that F76 must also equal "Probability-Sculpted"?

That would be the final trick that'd solve this for me...

The code above works splendidly though! Many thanks.
 
Upvote 0
You might need to amend the criteria for your ElseIf statement, depending on your actual requirement, but try...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$F$74" Or Target.Address = "$F$76" Then
        Application.EnableEvents = False
        If Me.Range("F74").Value = 1 And Me.Range("F76").Value = "Probability-Sculpted" Then
            Worksheets("Structuring").ChartObjects("Chart 3").Visible = False
        ElseIf Me.Range("F74").Value = 0 Then
            Worksheets("Structuring").ChartObjects("Chart 3").Visible = True
        End If
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0
Here's my updated ElseIf statement:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)    If Target.Address = "$F$74" Or Target.Address = "$F$76" Then
        Application.EnableEvents = False
        If Me.Range("F74").Value = 0 And Me.Range("F76").Value = "Probability-Sculpted" Then
            Worksheets("Structuring").ChartObjects("Chart 3").Visible = True
        ElseIf Me.Range("F74").Value = 1 And Me.Range("F76").Value <> "Probability-Sculpted" Then
            Worksheets("Structuring").ChartObjects("Chart 3").Visible = False
        End If
        Application.EnableEvents = True
    End If
End Sub

For whatever reason it won't toggle the chart for the "Probability-Sculpted" segment. If I toggle F74 to 1 and back to 0 and have F76 to something other than the Sculpted setting it won't show the chart, but when I then keep F74 as 0 and toggle to Sculpted and then toggle back to something else, it keeps the chart.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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