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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Snakehips

Well-known Member
Joined
May 17, 2009
Messages
5,236
Office Version
  1. 2013
Platform
  1. Windows
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:

jeff106

New Member
Joined
Dec 2, 2016
Messages
21
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.
 

Snakehips

Well-known Member
Joined
May 17, 2009
Messages
5,236
Office Version
  1. 2013
Platform
  1. Windows
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!
 

Watch MrExcel Video

Forum statistics

Threads
1,133,531
Messages
5,659,360
Members
418,499
Latest member
mbcmel

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