Adena Goldrich
Adena Goldrich

Reputation: 19

Excel 2010 Macro to Create Charts

I am trying to create macros to build charts in Excel 2010.

If I record a macro it gives me the following code:

ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("'Sheet1'!$A$1:$I$15")
ActiveChart.ChartType = xlColumnStacked

But when I rerun it, it gives me the following error:

Run time error '1004': Application defined or object defined error.

I have tried many different variations:

With ActiveSheet.ChartObjects.Add _
        (Left:=100, Width:=690, Top:=75, Height:=375)
    With .Chart
       .Parent.Name = "Chart MVO"
       .HasTitle = True
       .ChartTitle.Text = "MVO (628) CF and DS Delivery Performance"
    End With
 End With

But each gives a different run time error. What am I doing wrong?

Upvotes: 1

Views: 6536

Answers (1)

martin
martin

Reputation: 2638

Didn't you rename your sheet? Are you sure that you have a sheet active? When I try your code it runs without problem.

When you run your code and it gives you an error, choose Debug in the window that appears and check what line it crashes on. Then hover your mouse over different variables on that line and see if all of them are valid.

Upvotes: 3

Related Questions