prima satria
Board Regular
- Joined
- Nov 3, 2007
- Messages
- 63
I made a button with vba code to run / produce a graph as a new sheet name "CHART X"
Sub CHART_SHEET()
Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("ITEM CUMMU.").Range("A8:D11"), _
PlotBy:=xlColumns
ActiveChart.SeriesCollection(1).Name = "='ITEM CUMMU.'!R7C2"
ActiveChart.SeriesCollection(2).Name = "='ITEM CUMMU.'!R7C3"
ActiveChart.SeriesCollection(3).Name = "='ITEM CUMMU.'!R7C4"
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="CHART X"
End Sub
it works, but the problem is when I run the button twice, the debug statement appears, and when click end button, it will produce a new sheet with the same chart.
What I want with the "chart" button is, when the sheets name "CHART X" already available the code won't run a new sheet, but can only go to the sheets "CHART X".
Is there anyone could help ? thx in advance.
Sub CHART_SHEET()
Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("ITEM CUMMU.").Range("A8:D11"), _
PlotBy:=xlColumns
ActiveChart.SeriesCollection(1).Name = "='ITEM CUMMU.'!R7C2"
ActiveChart.SeriesCollection(2).Name = "='ITEM CUMMU.'!R7C3"
ActiveChart.SeriesCollection(3).Name = "='ITEM CUMMU.'!R7C4"
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="CHART X"
End Sub
it works, but the problem is when I run the button twice, the debug statement appears, and when click end button, it will produce a new sheet with the same chart.
What I want with the "chart" button is, when the sheets name "CHART X" already available the code won't run a new sheet, but can only go to the sheets "CHART X".
Is there anyone could help ? thx in advance.