Problem running macro when cell value changes due to option box selection

Jed Shields

Active Member
Joined
Sep 7, 2011
Messages
283
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I've got two option buttons that are linked to cell V1, giving a 1 or 2 depending on which button is pressed. If the top button is pressed the I want to hide Chart 2. If the bottom button is pressed the I want to show Chart 2. ChartOnOff works perfectly if I manually run it but I can't ge it to run automatically when the cell value changes. Any ideas?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Not Intersect(Target, Target.Worksheet.Range("V1")) Is Nothing Then ChartOnOff
    
End Sub


Sub ChartOnOff()

'Application.ScreenUpdating = False


   If Sheet19.Range("v1") = "1" Then
   
        Chart2FormatRemove
   
   End If
   
   
    If Sheet19.Range("v1") = "2" Then
   
        Chart2FormatAdd
   
   End If
End Sub



Sub Chart2FormatRemove()

    ChartObjects("chart 2").Visible = False
    
End Sub


Sub Chart2FormatAdd()

    ChartObjects("chart 2").Visible = True
    
End Sub
 
Last edited:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Option Buttons do not trigger change events.
If they are form controls, simply assign the "ChartOnOff" macro to both buttons.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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