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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
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!
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
Krisna

Worked for me when I changed the order.

Do you have data in the ranges specified?


Tony
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,254
Members
448,556
Latest member
peterhess2002

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
Back
Top