Reputation: 1
i made a chart on my excel sheet, and i want the user not to be able to delete it...
how can i do it?
I already tried this options from here:
https://peltiertech.com/Excel/ChartsHowTo/ChartProtection.html
The code is like this:
'Draw a chart
Dim rng As range
Dim cht As ChartObject
'Your data range for the chart
Set rng = Worksheets("Sheet1").range("$A$2:$A$100")
'Activate chart
Worksheets("Sheet1").ChartObjects(1).Activate
'Populate chart with data
ActiveChart.SetSourceData Source:=rng
'Determine type
ActiveChart.SeriesCollection.NewSeries.ChartType = xlLineMarkers
'Delete the 5th series
If ActiveChart.SeriesCollection.Count = 5 Then
ActiveChart.SeriesCollection(5).Delete
End If
I need something like this:
ActiveChart.preventDeleting
Now, the protection I had in mind was to prevent the user, from actively deleting the chart....a simple select and remove, or button press delete, or something...
In simple terms, block any attempt to delete the chart...
But, i dont know if this is relevant, but the table can change its range, and the chart should be still able to get updated...
Please let me know, if you need something else...
Also, it does not nessesary need to be a vba code, it can also be a manual solution, I am using MS excel 2007
Thanks...
Upvotes: 0
Views: 433
Reputation: 9878
You can protect the chart by protecting the sheet. If you want the user to be able to edit some of the cells, simply right click on the cells that you want to be able to be edited and select Format Cells -> Protection -> Locked
and make sure this is unchecked.
Then protect the worksheet via Review -> Protect Sheet
on the menu bar. This will prevent the deletion of the chart and allow users to continue editing the cell content
Upvotes: 2