VBA Help! How to enable toggle button in a protected sheet

Alfredathavan

New Member
Joined
Jun 19, 2021
Messages
1
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
  2. Web
Hi I'm trying to insert a toggle button to hide/unhide columns but it has to be protected.

The code that I found protect/unprotect upon clicking the button to hide/unhide which is not what I want.

I need the toggle button to just hide/unhide in a protected sheet which cannot be unprotected by other users.

Below is the full code:



Private Sub Choose_Click()

End Sub

Private Sub ToggleButton1_Click()
Dim xAddress As String
xAddress = "L:M"
If ToggleButton1.Value Then
Application.ActiveSheet.Columns(xAddress).Hidden = True
Else
Application.ActiveSheet.Columns(xAddress).Hidden = False
End If
End Sub

Private Sub ToggleButton2_Click()
Dim xAddress As String
xAddress = "O:U"
If ToggleButton2.Value Then
Application.ActiveSheet.Columns(xAddress).Hidden = True
Else
Application.ActiveSheet.Columns(xAddress).Hidden = False
End If
End Sub


Private Sub ToggleButton3_Click()
Dim xAddress As String
xAddress = "S"
If ToggleButton3.Value Then
Application.ActiveSheet.Columns(xAddress).Hidden = True
Else
Application.ActiveSheet.Columns(xAddress).Hidden = False
End If
End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
This is how you can protect the sheet from being changed by users but VBA code can still edit
VBA Code:
Sheet1.Protect userinterfaceonly:=True, Password:="MyPassword"
 
Upvote 0

Forum statistics

Threads
1,214,839
Messages
6,121,887
Members
449,057
Latest member
Moo4247

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