Hello
The macro to create the chart works fine all the time the sheet's unprotected. As soon as it's protected, it reports a runtime error 1004. Specified value out of range.
I've Googled trying to find an answer, but they're all as clear as mud to me.
Attached is the macro debug screen
Running Excel 2010
Thanks
Last edited by Philb1; 09-16-2011 at 05:12 PM.
Hi,
Add a first line to your macro code
and add a last lineActiveSheet.Unprotect
RegardsActiveSheet.Protect
Richard Buttrey
If this was useful then please rate it appropriately.
Click the small star iconat the bottom left of my post.
Hi Richard, Thanks for the reply
It worked. But. The macro requires the password to unprotect the sheet, it creates the chart, pastes it onto another sheet & then protects the wrong sheet.
I would like it to not require the password & to re lock the sheet the macro started from. I've uploaded a sample for you to play with
Thanks
Hi,
Try the attached
RegardsSub Macro1() Dim shChart As Worksheet, oChart As Object Set shChart = Sheet1 shChart.Unprotect Password:="help" Set oChart = shChart.Shapes.AddChart oChart.Select ActiveChart.ApplyChartTemplate ( _ "C:\Users\Phil\AppData\Roaming\Microsoft\Templates\Charts\DefaultChart1.crtx") ActiveChart.SetSourceData Source:=Range("Charts!$B$3:$D$10") oChart.Cut With Sheets("View").Range("F3") .Parent.Paste End With shChart.Protect Password:="help" End Sub
Richard Buttrey
If this was useful then please rate it appropriately.
Click the small star iconat the bottom left of my post.
Thanks for your help Richard
I came up with this
It works. I'll try your solution tooSub Macro1() ' ' Macro1 Macro ' ' ActiveSheet.Unprotect "help" Set MyPlotRange = Selection ActiveSheet.Shapes.AddChart.Select ActiveChart.ApplyChartTemplate ( _ "C:\Users\Phil\AppData\Roaming\Microsoft\Templates\Charts\DefaultChart1.crtx") ActiveChart.SetSourceData Source:=MyPlotRange ActiveChart.Parent.Cut Sheets("View").Select Range("F3").Select ActiveSheet.Paste Sheets("Charts").Select ActiveSheet.Protect "help" Sheets("View").Select End Sub
Cheers
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks