Can’t Set Minimum Scale of a Chart when Worksheet is Protected

Nouveau

New Member
Joined
Jul 1, 2022
Messages
7
Office Version
  1. 365
Platform
  1. MacOS
I have a macro in a protected worksheet that performs some calculations and updates a chart when the worksheet is activated by clicking on its tab. Within this macro, I set the minimum value of the chart's X-axis using the following command:

ActiveSheet.ChartObjects("Chart 3").Chart.Axes(xlCategory).MinimumScale = WorksheetFunction.Min(Range("U5:U7"))

Everything works perfectly when the worksheet is unprotected. When I protect the sheet, the code stops at this line and I get an error that says, “Method ‘MinimumScale’ of Object ‘Axis’ failed”

I tried to give the user permission to Edit Objects when the sheet is protected, but that doesn’t seem to work.

I suppose I could unprotect the sheet at the beginning of the macro and then protect it again at the end, but I hate to open a vulnerability. Is there a better way to do this, please? Thank you.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
This will leave the user interface protected while allowing your macro to run. Then, once finished, it protects both the user interface and macros.

VBA Code:
    ThisWorkbook.Worksheets("Sheet1").Protect Password:="YourPassword", UserInterfaceOnly:=True

    'your code here
   
    ThisWorkbook.Worksheets("Sheet1").Protect Password:="YourPassword", UserInterfaceOnly:=False

Hope this helps!
 
Upvote 0
Solution
Yes, that worked Domenic. In my case, I put these just before and just after the ActiveSheet.ChartObjects line, leaving the rest of the sheet protected for most of the macro execution.

It's interesting that I have to do this when I can make other changes to the sheet while it's protected. This is the only line giving me trouble.

Thank you for your help.
 
Upvote 0
VBA Code:
  ThisWorkbook.Worksheets("Sheet1").Protect Password:="YourPassword", UserInterfaceOnly:=True

With the above line, the worksheet remains protected throughout the macro, even when executing your line of code. It's only macros that are not protected.

VBA Code:
    ThisWorkbook.Worksheets("Sheet1").Protect Password:="YourPassword", UserInterfaceOnly:=False

With the above line, macros become protected again so that now both the user interface and macros are protected.
 
Upvote 0
I didn't know about the UserInterfaceOnly option and learned something from you. Thanks.
 
Upvote 0

Forum statistics

Threads
1,215,486
Messages
6,125,070
Members
449,205
Latest member
Healthydogs

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