Protect worksheet cells but still allow macro to edit chartproperties

R

rrj

I have a worksheet with calculations and charts.
The calculations refer to data in a separate worksheet that can be
overwritten by loading new data from a csv file.
I've written a macro to do this.
When I load the data I rescale the charts from the macro to best
visualise the new data set
There are then some parameters next to the charts which the user can
modify to optimise the result.
Everything works fine, but now I want to protect the calculations.
I can choose which cells to lock/unlock and then protect the sheet.

The chart axis scales can still be edited by the user, but the problem
is that the macro to rescale the chart then fails.

In its simplest form it looks like this

ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Axes(xlValue).MinimumScale = "something"

I get the message Run-time error '1004', application-defined or object-
defined error.
Its the activate that fails, not the scale change.
Its there any way of working around this?

Thanks
Richard
 
P

Per Jessen

Hi Richard

You have to unprotect first:

pWord = "JustMe"
ActiveSheet.Unprotect Password:=pWord
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Axes(xlValue).MinimumScale = "something"
ActiveSheet.Protect Password:="pWord"

Hopest this helps
 
R

rrj

Hi Richard

You have to unprotect first:

pWord = "JustMe"
ActiveSheet.Unprotect Password:=pWord
ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.Axes(xlValue).MinimumScale = "something"
ActiveSheet.Protect Password:="pWord"

Hopest this helps

Thanks Per,

That does help, but is there any way to unprotect just the chart?

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top