CloudenL
12-20-2011, 11:04 AM
I have a file that i inherited at work and i'm trying to understand what all the code does. there is a tab that will create charts, you are supposed to click on a chart area and hit a button for either line, pie or bar. the macro runs if im in the VB screen and hit run, but not if i am on the actual excel page. it automatically jumps to the "error" statement, even though i have clicked on the chart area. Im not sure what is wrong with this code and was hoping someone could help with what is missing.
I tried doing my own macro to change chart type to see what it looks like, and it gives me:
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.PlotArea.Select
ActiveChart.ChartType = xlPie
which is fine, but "chart 2" is the chart i selected, similar to below where it says ActiveSheet.ChartObjects("Chart 5").Activate. but i have 5 different charts, so im thinking having it say "Chart 5" is part of the problem, but i am not totally sure since i am still trying to learn.
Sub ChangeChartType()
ActiveSheet.ChartObjects("Chart 5").Activate
ActiveChart.SeriesCollection(1).Select
ActiveChart.ChartArea.Select
ActiveChart.ChartType = xlBarClustered
ActiveChart.ChartType = xlLineMarkers
ActiveChart.ChartType = xlColumnClustered
ActiveChart.ChartType = xlPie
End Sub
Sub LineChart()
On Error GoTo LineChartERR
ActiveChart.ChartType = xlLineMarkers
Exit Sub
LineChartERR:
vERR = MsgBox("SELECT A CHART BEFORE CLICKING HERE")
End Sub
I tried doing my own macro to change chart type to see what it looks like, and it gives me:
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.PlotArea.Select
ActiveChart.ChartType = xlPie
which is fine, but "chart 2" is the chart i selected, similar to below where it says ActiveSheet.ChartObjects("Chart 5").Activate. but i have 5 different charts, so im thinking having it say "Chart 5" is part of the problem, but i am not totally sure since i am still trying to learn.
Sub ChangeChartType()
ActiveSheet.ChartObjects("Chart 5").Activate
ActiveChart.SeriesCollection(1).Select
ActiveChart.ChartArea.Select
ActiveChart.ChartType = xlBarClustered
ActiveChart.ChartType = xlLineMarkers
ActiveChart.ChartType = xlColumnClustered
ActiveChart.ChartType = xlPie
End Sub
Sub LineChart()
On Error GoTo LineChartERR
ActiveChart.ChartType = xlLineMarkers
Exit Sub
LineChartERR:
vERR = MsgBox("SELECT A CHART BEFORE CLICKING HERE")
End Sub