Custom Views: Hide columns not working when sheet is protected

cellist

New Member
Joined
Jan 6, 2008
Messages
23
Using Custom Views in a protected worksheet, the column hiding/unhiding implicit in the views does not occur. The following error message is displayed:

Some view settings could not be applied​

In the Add View dialog box, I've checked the "Hidden rows, columns and filter settings" option.

In the protection dialog box, I've checked the checkbox for "Format Columns", which I believe indicates that hiding/unhiding columns is permitted when the sheet is protected. And, when the sheet is protected, I can manually hide and unhide columns, but I want that to happen automatically when I select the custom view.

If I unprotect the worksheet, column hiding/unhiding occurs automatically when I select the custom view.

Can I write code to make the column hiding and unhiding occur when the view is selected, perhaps by unprotecting the sheet temporarily and then protecting it again once the selected view has been displayed?
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
You can use something like
Code:
Worksheets("name here").Unprotect "password here"

'code here

Worksheets("name here").Protect "password here"

To get the code to unhide/hide the views use the Macro Recorder
 
Upvote 0
Worksheets("name here").Unprotect "password here"

'code here

Worksheets("name here").Protect "password here"

Thanks for your reply royUK.

Your code example will be helpful. Do you know where -- what action or event handler -- I can put my code, so that it is triggered when the user selects the desired custom view using View>Custom View>Show? Or will I need to add my own control and write code specifically to replace View>Custom View>Show?

And thanks for reminding me to make use of the macro recorder for "uncharted territory". I do very little VBA coding from scratch and don't always remember to make use of that resource.

Phil
 
Upvote 0
Hi Phil
I would suggest that you remove Protection iniially, then record a macro to display a view. Then edit it as necessary and incorporate the protect/unprotect code. Use a keyboard shortcut or button to run the code.
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,453
Members
448,898
Latest member
drewmorgan128

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