Error with toggle button

Guinaba

Board Regular
Joined
Sep 19, 2018
Messages
217
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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Why do you need the "With" Toggle button. Can't it just be If Toggle value is true then...
 
Upvote 0
It's not working.

How many lines are we talking about 2 or 3?
 
Upvote 0
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
 
Upvote 0
Solution
I am glad you got it working. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,315
Members
449,081
Latest member
tanurai

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