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
 
The data's there. And I even saw it've got those columns selected! :(
Or maybe cuz i moved the series as below?

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

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
Tony, you are right! it worked when I kept the range like Range("B1:E11,G1:G11") and removed the lines for switching first n second Y axis as following:

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"

Still, i'd like to switch anyways. Is there any other way to work this out?
 
Upvote 0

Forum statistics

Threads
1,215,007
Messages
6,122,670
Members
449,091
Latest member
peppernaut

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