-5

I want to create a button in Excel, which, on clicking shows/hides the Graph on the sheet. I have created a button by watching the Excel tutorials, but how to write the code and how to link that code to the respective button. I'm novice in excel coding. Help is highly appreciated.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Yash R.
  • 13
  • 1
  • 10
  • 3
    Please read: [Create a Macro](https://www.excel-easy.com/vba/create-a-macro.html). There are at least 1000 tutorials explaining exactly that. – Pᴇʜ May 28 '18 at 07:01

1 Answers1

0

You can insert an activeX button and add this following code :

If ChartObjects("chart 1").Visible = True Then
ChartObjects("chart 1").Visible = False
Else
ChartObjects("chart 1").Visible = True
End If

"chart 1" is Graph default name. You will probably need to change it.

Best regards

JC Guidicelli
  • 1,296
  • 7
  • 16
  • you would never want to use an *ActiveX* button if you can use a *Form Control* button instead. Stay away from ActiveX if possible. See [What is the difference between “Form Controls” and “ActiveX Control” in Excel 2010?](https://stackoverflow.com/questions/15455179/what-is-the-difference-between-form-controls-and-activex-control-in-excel-20) – Pᴇʜ May 28 '18 at 09:41