Hide/unhide columns of multiple sheets using tickbox

bakarken

Board Regular
Joined
Sep 23, 2016
Messages
50
Office Version
  1. 2019
Platform
  1. Windows
Hello

I have a tickbox in Sheet1 and I would like a VBA that when this is ticked, columns H:M in ALL of Sheet2, Sheet3, Sheet4 and Sheet5 will hide. Then if this box is unchecked, they will reveal themselves.

I've seen examples where a VBA can apply to a single sheet, but is there a way it can be applied to multiple sheets?

Thanks
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try:

Code:
Private Sub CheckBox1_Click()
    Application.ScreenUpdating = False
    shs = Array("sheet2", "sheet3", "sheet4", "sheet5")
    For i = LBound(shs) To UBound(shs)
        Sheets(CStr(shs(i))).Unprotect "abc"
        Sheets(CStr(shs(i))).Columns("H:M").EntireColumn.Hidden = CheckBox1
        Sheets(CStr(shs(i))).Protect "abc"
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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