Hide a Column in All Worksheets when Opening the Workbook

nryan

Board Regular
Joined
Apr 3, 2015
Messages
61
I'd like to hide column "B" for all worksheets and set the Row height to 15 for all worksheets when I open the workbook. I tried a For Next Loop but I'm encountering run-time errors. Here's the code:

Code:
Sub Workbook_Open()

    Dim ws As Worksheet
    
    For Each ws In ThisWorkbook.Worksheets
        ws.Range("A2:A" & ws.Rows.Count).RowHeight = 15
        ws.Columns("B").Hidden = True
        ws.Protect Password:="wmd", Userinterfaceonly:=True
    Next ws
    
End Sub

Originally I had this code which worked:

Code:
Sub Workbook_Open()

    Dim ws As Worksheet
    
    For Each ws In ThisWorkbook.Worksheets
        ws.Protect Password:="wmd", Userinterfaceonly:=True
    Next ws
    
End Sub

I just tried adding onto it. Any help would be great.

Thank you.
-Nick
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
try this:
Code:
Sub Workbook_Open()

    Dim ws As Worksheet
    
    For Each ws In ThisWorkbook.Worksheets
        ws.Range("A2:A" & ws.Rows.Count).RowHeight = 15
        ws.Columns(2).Hidden = True
        ws.Protect Password:="wmd", Userinterfaceonly:=True
    Next ws
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,510
Messages
6,125,223
Members
449,216
Latest member
biglake87

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