macro doesn't work in all the sheets

May 23, 2011 at 14:22:07
Specs: Windows 7
I designed a macho to make a graph but it only work if I am in the work sheet where I made the macro. All the sheets have different names. The macro is:

Sub Macro3()
' Macro1 Macro
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterSmooth
ActiveChart.Parent.Cut
ActiveSheet.Paste
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Name = "='NL SG 51211-1'!$B$15"
ActiveChart.SeriesCollection(1).XValues = "='NL SG 51211-1'!$B$61:$B$9508"
ActiveChart.SeriesCollection(1).Values = "='NL SG 51211-1'!$C$61:$C$9508"
End Sub

What can I do so the macro work in any worksheet?


See More: macro doesnt work in all the sheets

Report •


#1
May 23, 2011 at 17:27:52
Not tested:

I removed the reference to the sheet name, leaving just the range of cells.

Does that work for you?

Sub Macro3()
' Macro1 Macro
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterSmooth
ActiveChart.Parent.Cut
ActiveSheet.Paste
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Name = "=$B$15"
ActiveChart.SeriesCollection(1).XValues = "=$B$61:$B$9508"
ActiveChart.SeriesCollection(1).Values = "=$C$61:$C$9508"
End Sub 

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

#2
May 24, 2011 at 06:06:26
Thank you DerbyDad03 for answering my question. But I try to run the macro with the solution that you post and it did not work.

Thank you again


Report •

Related Solutions


Ask Question