Call Private Sub ToggleButton1_Click()

Mindlesh

Board Regular
Joined
Apr 2, 2014
Messages
172
When I call ToggleButton1_Click, why are the columns not toggled in the way that they are when I click the button?
Code:
Private Sub ToggleButton1_Click()
    With ActiveSheet.ListObjects("Table4")
        .ListColumns("Ti").DataBodyRange.EntireColumn.Hidden = Not (ToggleButton1.Value)
        .ListColumns("Ne").DataBodyRange.EntireColumn.Hidden = Not (ToggleButton1.Value)
    End With
End Sub

Private Sub CommandButton1_Click()
    Application.Run "Sheet8.ToggleButton1_Click"
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I solved the error by adding data to the table (doh!), but still cannot execute the toggle button macro via the command button.
 
Upvote 0
Is the sub accessible from the page you are calling it from, has the toggle name changed (properties)
 
Upvote 0
What seems to be happening in the workbook (after I have added data to the table):
  1. Clicking the command button hides the columns; the toggle button macro is executed, but it only works once.
  2. When the columns are hidden (what would be the default state), clicking the command button fails to unhide them.
I suppose what I need is for the command button macro to detect that the toggle button has not been clicked, and only then click it to unhide the columns.
 
Upvote 0
I'm not sure how to make the test for hidden to allow the toggle to work both ways (its possible) I just don't know
 
Upvote 0
When you click on the command button, it runs the click event for the toggle button, but its state or value doesn't get changed. I think you can replace...

Code:
Application.Run "Sheet8.ToggleButton1_Click"

with

Code:
Me.ToggleButton1.Value = Not Me.ToggleButton1.Value
 
Upvote 0

Forum statistics

Threads
1,214,962
Messages
6,122,482
Members
449,088
Latest member
Melvetica

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