Cannot get multiple toggle buttons to hide/unhide specific columns

jeff106

New Member
Joined
Dec 2, 2016
Messages
21
Hi,
I have a sheet with columns A-AZ with each column being specific to information being inputted about different businesses in rows 2-75.
For ease of matching column Z (for example) with the respective row number in view, I want to be able to have multiple toggle buttons that can hide/unhide specific columns. Currently I have one toggle button that hides Columns L:S and also unhides it. It works great. My issue comes when I try to add in a second or third toggle button. I'd like the second toggle button to hide and unhide columns D:F. Below is the code I used for the first toggle button. I simply copied the code and used it for the second button. However, when doing so, the second toggle button only HIDES and does not UNHIDE columns D:F. Can anyone help with this please?


Private Sub ToggleButton1_Click()
Dim xAddress As String
xAddress = "L:S"
If ToggleButton1.Value Then
Application.ActiveSheet.Columns(xAddress).Hidden = True
ToggleButton1.Caption = "Show Addt'l BSV"
Else
Application.ActiveSheet.Columns(xAddress).Hidden = False
ToggleButton1.Caption = "Hide Addt'l BSV"
End If
End Sub
Private Sub ToggleButton2_Click()
Dim xAddress As String
xAddress = "D:F"
If ToggleButton1.Value Then
Application.ActiveSheet.Columns(xAddress).Hidden = True
ToggleButton2.Caption = "Show Rest. Characteristics"
Else
Application.ActiveSheet.Columns(xAddress).Hidden = False
ToggleButton2.Caption = "Hide Rest. Characteristics"
End If
End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
jeff106,

Welcome to MrExcel.

Try fixing typo for button name...

Rich (BB code):
Private Sub ToggleButton2_Click()
Dim xAddress As String
xAddress = "D:F"
If ToggleButton2.Value Then
Application.ActiveSheet.Columns(xAddress).Hidden = True
ToggleButton2.Caption = "Show Rest. Characteristics"
Else
Application.ActiveSheet.Columns(xAddress).Hidden = False
ToggleButton2.Caption = "Hide Rest. Characteristics"
End If
End Sub

Hope that helps.
 
Last edited:
Upvote 0
THANK YOU
That is really embarrassing. I'm so sorry for taking up your time for that. BUT THANK YOU!

jeff106,

Welcome to MrExcel.

Try fixing typo for button name...

Rich (BB code):
Private Sub ToggleButton2_Click()
Dim xAddress As String
xAddress = "D:F"
If ToggleButton2.Value Then
Application.ActiveSheet.Columns(xAddress).Hidden = True
ToggleButton2.Caption = "Show Rest. Characteristics"
Else
Application.ActiveSheet.Columns(xAddress).Hidden = False
ToggleButton2.Caption = "Hide Rest. Characteristics"
End If
End Sub

Hope that helps.
 
Upvote 0
THANK YOU
That is really embarrassing. I'm so sorry for taking up your time for that. BUT THANK YOU!

You are welcome. Don't be embarrassed we have all done it, tearing your hair out, scrutinising logic over and over and missing a typo!
 
Upvote 0

Forum statistics

Threads
1,213,486
Messages
6,113,932
Members
448,533
Latest member
thietbibeboiwasaco

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