vbaexcel

Changing chart types with vba


Hi there i would like to use vba to change a pie chart to a bar chart and vice versa . I have used this code from a similar question but it does not seem to work. It gives me a system error message saying "parameter not found". When i run it from the developer itself,it gives me a run time error 5. Need help to debug this or a code to help change chart types.Thank you. Here is the code:

Sub ApplyPieChart()
    ActiveSheet.ChartObjects("Chart Title").Activate
    ActiveChart.ChartType = xlPie
End Sub

Sub ApplyBarChart()
    ActiveSheet.ChartObjects("Chart Title").Activate
    ActiveChart.ChartType = xlBarClustered
End Sub

Solution

  • The code runs without error for me. Check the name of the chart. Most likely it is not "Chart Title" but something like "Chart 1", unless you changed it.

    enter image description here