Error with toggle button

Guinaba

Board Regular
Joined
Sep 19, 2018
Messages
155
Office Version
  1. 2016
Platform
  1. Windows
Hi guys,

I used two have two buttons (Form Control) to show/hide a chart named ("Graph") which was perfectly working. However, I've decided to replace the two buttons with a toggle button (ActiveX Control) and now I keep getting the error: The item with the specified name wasn't found, I am assuming the button doesn's recognize the chart("Graph"). Any suggestions?

1625447285856.png


VBA Code:
Private Sub ToggleButton2_Click()
 With ToggleButton2
   If .Value=true Then
      .Caption = "Hide Graph"
      .BackColor = vbRed
      Sheets("Summary").ChartObjects("Graph").Visible = True
      Sheets("Summary").ChartObjects("Graph").Activate
      Sheets("Summary").ChartObjects("Graph").Cut
      Sheets("Summary").Paste
      Sheets("Summary").ChartObjects("Graph").Height = 460
      Sheets("Summary").ChartObjects("Graph").Width = 1300
     
      Growth.Show vbModeless
      Growth.StartUpPosition = 0
      Growth.Top = Application.Top + 50
      Growth.Left = Application.Left + Application.Width - Growth.Width - 400
      
    Else
      .Caption = "Show Graph"
      .BackColor = vbGreen
      Sheets("Summary").ChartObjects("Graph").Visible = False
      Growth.Hide
      Unload Growth
    End If
  End With
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

igold

Well-known Member
Joined
Jul 8, 2014
Messages
2,695
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Why do you need the "With" Toggle button. Can't it just be If Toggle value is true then...
 

igold

Well-known Member
Joined
Jul 8, 2014
Messages
2,695
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
It's not working.

How many lines are we talking about 2 or 3?
 

Guinaba

Board Regular
Joined
Sep 19, 2018
Messages
155
Office Version
  1. 2016
Platform
  1. Windows
Hi @igold,

I've changed the code, it seem ok now.

VBA Code:
If ActiveSheet.ToggleGraph.Value = False Then
       ActiveSheet.ToggleGraph.Caption = "Show Graph"
       ActiveSheet.ToggleGraph.BackColor = vbGreen
       ActiveSheet.ChartObjects("Graph").Visible = False
       Growth.Hide
       Unload Growth
    Else
       ActiveSheet.ToggleGraph.Value = True
       ActiveSheet.ToggleGraph.Caption = "Hide Graph"
       ActiveSheet.ToggleGraph.BackColor = vbRed
       ActiveSheet.ChartObjects("Graph").Visible = True
       Sheets("Summary").ChartObjects("Graph").Activate
       Sheets("Summary").ChartObjects("Graph").Cut
       Sheets("Summary").Paste
       Growth.Show vbModeless
       Growth.StartUpPosition = 0
       Growth.Top = Application.Top + 50
       Growth.Left = Application.Left + Application.Width - Growth.Width - 400
End If
 
Solution

igold

Well-known Member
Joined
Jul 8, 2014
Messages
2,695
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I am glad you got it working. Thanks for the feedback.
 

Forum statistics

Threads
1,141,402
Messages
5,706,232
Members
421,433
Latest member
yash0468

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
Top