Creating Chart in Macro problem

cheakrisna

New Member
Joined
Jan 15, 2005
Messages
22
I got a "Run-time error '1004': Method 'Axes' of object '_Chart' failed" dialog everytime i run the macro below

Sub creatingchart()

Charts.Add
ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:= _
"Line - Column on 2 Axes"
ActiveChart.SetSourceData Source:=Sheets("don").Range("B1:E11,G1:G11"), _
PlotBy:=xlColumns
ActiveChart.SeriesCollection(1).Delete
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(2).XValues = "=don!R2C2:R11C4"
ActiveChart.SeriesCollection(2).Values = "=don!R2C5:R11C5"
ActiveChart.SeriesCollection(2).Name = "=don!R1C5"
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="Chart1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Title"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = _
"Category"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "MB/sec"
.Axes(xlCategory, xlSecondary).HasTitle = False '*****got error****
.Axes(xlValue, xlSecondary).HasTitle = True
.Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = _
"Log times"
End With
end sub

It seems that excel doesn't support this type of chart. Please help :rolleyes:
I'd appreciate it.
Chris
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Tazguy37

MrExcel MVP
Joined
May 28, 2004
Messages
4,237

ADVERTISEMENT

The chart type is OK, I can create one myself in XL2000. Looking through your code, I don't think you need this line:
Code:
.Axes(xlCategory, xlSecondary).HasTitle = False
You might try commenting it out and see what happens. Hope that helps!
 

cheakrisna

New Member
Joined
Jan 15, 2005
Messages
22
nope, i've commented that line out, still the error went to the next line below it. It seems not to support secondary axis or something.

Thank you though. :(
Chris
 

acw

MrExcel MVP
Joined
Feb 13, 2004
Messages
4,814

ADVERTISEMENT

Hi

Try putting the lines below in this order ie put the chart type after the chart has been created.

ActiveChart.SetSourceData Source:=Sheets("don").Range("B1:E11,G1:G11"), PlotBy:=xlColumns
ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:="Line - Column on 2 Axes"

Tony
 

acw

MrExcel MVP
Joined
Feb 13, 2004
Messages
4,814
Krisna

Worked for me when I changed the order.

Do you have data in the ranges specified?


Tony
 

acw

MrExcel MVP
Joined
Feb 13, 2004
Messages
4,814
Krisna

Tried again. When there was no data, I got an error. When there was data in the source range, worked OK with the 2 lines changed.


Tony
 

Forum statistics

Threads
1,147,508
Messages
5,741,570
Members
423,668
Latest member
Audorin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top