VBA on Protected Sheets: Allow Specific Formatting Only?

CUT3dge
NewLounger
Posts: 3
Joined: 23 Feb 2024, 20:49

VBA on Protected Sheets: Allow Specific Formatting Only?

Post by CUT3dge »

tldr:
I'm looking for a VBA code to restrict formatting for specific cells' fonts & borders, but allows data entry, merge cells & fill color changes on these cells.


Some background:
I'm creating a new purchase order workbook that has a pre-formatted pivot table that pulls the purchase codes & totals from the entire workbook (40 sheets in total max; # of sheets will never be more or less as these files are only used for the month, then a new one is started). The employee who will be using these files, seems to have an issue with frequently changing the formatting on cells (accidentally deleting formulas, copy & pasting cells so the borders will change, etc.). With this pivot table I've added, these type of changes can obviously screw it up pretty royally, and I want to prevent as much headache as I can going forward by being able to restrict what she can/can't do on this new file. Is there a VBA code that anyone is familiar with that would allow data entry, merge cells and fill colour to be used but locks formatting fonts & borders of specific cells only?

User avatar
HansV
Administrator
Posts: 78568
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA on Protected Sheets: Allow Specific Formatting Only?

Post by HansV »

Welcome to Eileen's Lounge!

Since Excel lumps all cell formatting together in the Protect Sheet dialog, it's not easy to allow some aspects (fill color) but not others (font, borders).
Education is probably your best bet!
Best wishes,
Hans

CUT3dge
NewLounger
Posts: 3
Joined: 23 Feb 2024, 20:49

Re: VBA on Protected Sheets: Allow Specific Formatting Only?

Post by CUT3dge »

HansV wrote:
23 Feb 2024, 21:47
Welcome to Eileen's Lounge!

Since Excel lumps all cell formatting together in the Protect Sheet dialog, it's not easy to allow some aspects (fill color) but not others (font, borders).
Education is probably your best bet!
Thanks so much :) I'm happy to have found such an active forum like this for guidance on these kinds of issues. :cheers:

Do you mean educating my self on VBA or educating the employee?

User avatar
HansV
Administrator
Posts: 78568
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA on Protected Sheets: Allow Specific Formatting Only?

Post by HansV »

I meant educating the employee.
For example, preventing pasting into unprotected cells is really complicated. Instruct the user to use Ctrl+Shift+V to paste values instead of clicking Paste or pressing Ctrl+V.
Best wishes,
Hans

CUT3dge
NewLounger
Posts: 3
Joined: 23 Feb 2024, 20:49

Re: VBA on Protected Sheets: Allow Specific Formatting Only?

Post by CUT3dge »

HansV wrote:
23 Feb 2024, 22:01
I meant educating the employee.
For example, preventing pasting into unprotected cells is really complicated. Instruct the user to use Ctrl+Shift+V to paste values instead of clicking Paste or pressing Ctrl+V.
Sadly, I have tried this quite a few times :( I've even made step by step tutorials for her to follow to show her how to fix/prevent these issues and anytime she does catch them herself, I will sit with her and guide her (as needed) while she's correcting them.
Surprisingly, she's currently at the end of a 1 year accounting course that she started before we hired her. She's versed in certain aspects of excel, but formatting consistency and not deleting cells with formulas seem to be something she has a hard time grasping or being consistent about (I can't even get her using keyboard commands for most things... she prefers to use right click and that drives me bananas :hairout: lol).

I do appreciate your suggestion though; I think I will take the weekend to think about some better ways to get her to understand the issues she's having, in tandem with protecting certain aspects of the workbook.

Tysm for your time and expertise on this! :)

User avatar
StuartR
Administrator
Posts: 12618
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: VBA on Protected Sheets: Allow Specific Formatting Only?

Post by StuartR »

An alternative approach is to lock all the cells that need to be displayed consistently, and provide some other way to input the data, for example have a separate data input sheet, or use a dialog box from VBA, or ...
StuartR