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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

mole999

Well-known Member
Joined
Oct 23, 2004
Messages
10,524
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
you should need at most (providing the right sheet is selected, or there is only one toggle named the same)

Private Sub CommandButton1_Click()
ToggleButton1_Click
End Sub
 
Upvote 0

Mindlesh

Board Regular
Joined
Apr 2, 2014
Messages
172
I have selected the right sheet number, and there is only one toggle. I have tested that ToggleButton1_Click is being called by alternating the button's caption, but still the columns are unaffected.
 
Upvote 0

mole999

Well-known Member
Joined
Oct 23, 2004
Messages
10,524
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
If you F8 can you follow the code following what you what when triggered
 
Upvote 0

Mindlesh

Board Regular
Joined
Apr 2, 2014
Messages
172
When I F8 it cycles through ToggleButton1_Click as expected.
 
Upvote 0

mole999

Well-known Member
Joined
Oct 23, 2004
Messages
10,524
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
so where in
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
does it fail
 
Upvote 0

Mindlesh

Board Regular
Joined
Apr 2, 2014
Messages
172
It fails completely; ie. neither column is toggled.
 
Upvote 0

mole999

Well-known Member
Joined
Oct 23, 2004
Messages
10,524
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
So it runs to the End Sub, but no action occurs, that what is established. Can you post a workbook somewhere that can be looked at (stripped down data). Need to test whats happening
 
Upvote 0

Mindlesh

Board Regular
Joined
Apr 2, 2014
Messages
172
I created a separate workbook, and it has yielded error 91: Object variable or With block variable not set. What do I need to do differently?
 
Upvote 0

mole999

Well-known Member
Joined
Oct 23, 2004
Messages
10,524
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
Using my vast guessing without seeing the problem skills, I would start by placing Option Explict at the very top of the code, so when you compile it will show errors
 
Upvote 0

Forum statistics

Threads
1,190,562
Messages
5,981,697
Members
439,731
Latest member
auraitsuka

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