Not allow users to hide columns in protected sheet

gubertu

Board Regular
Joined
May 24, 2015
Messages
148
Hi all,

I have a protected sheet, where I want the users to be able to change the size of the columns but not to hide them.

In the option "Protect sheet" I can unable "Format columns", but If I do that, the users will not be able to change the size of the columns.

Is there a code for this?

Thanks in advance!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
you could allow the users to hide the columns but unhide tehm when they deactivate the sheet by putting this in the worksheet deactivate event. ( I like the sneaky way this works!!)
Code:
Private Sub Worksheet_Deactivate()
Columns("A:Z").Hidden = False
End Sub
 
Last edited:
Upvote 0
Sub lockActiveSheetFormatColumns ()
ActiveSheet.Protect Password:="EnterPasswordHere", AllowFormattingColumns:=True
End Sub
 
Last edited:
Upvote 0
Thanks for the code! I think this is close to what I need.

It is possible that when I change to a sheet, is is forbidden to hide the columns?

Thanks!



you could allow the users to hide the columns but unhide tehm when they deactivate the sheet by putting this in the worksheet deactivate event. ( I like the sneaky way this works!!)
Code:
Private Sub Worksheet_Deactivate()
Columns("A:Z").Hidden = False
End Sub
 
Upvote 0
I had a further thought : you will also need to put this code in the workbook before save event, to prevent them savign the workbook with columns hidden:
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
For i = 1 To Worksheets.Count
 Worksheets(i).Columns("A:Z").Hidden = False
Next i
End Sub
 
Upvote 0
This code is great! I think it is enough for what I need. When someone tries to save the WB with a hidden columns, the columns just are unhidden right?

Thanks!



I had a further thought : you will also need to put this code in the workbook before save event, to prevent them savign the workbook with columns hidden:
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
For i = 1 To Worksheets.Count
 Worksheets(i).Columns("A:Z").Hidden = False
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,702
Messages
6,173,951
Members
452,539
Latest member
delvey

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