PC Review


Reply
 
 
=?Utf-8?B?ZXdhbjcyNzk=?=
Guest
Posts: n/a
 
      5th Sep 2007
Hi all,

I ensounter a runtime error 1004 'Method 'Axes' of object '_Chart' failed'
when I run this code (that I recorded):

Charts.Add
ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:="Lines on 2
Axes"
ActiveChart.SetSourceData Source:=Sheets("Gas").Range(FirstMonth,
LastMonth.Offset(0, 2)), PlotBy:=xlColumns
ActiveChart.SeriesCollection(1).Name = "=""Direct Cost Per Trade"""
ActiveChart.SeriesCollection(2).Name = "=""Total Direct Cost"""
ActiveChart.Location Where:=xlLocationAsObject, Name:="Gas Charts"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Financials"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Month"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Total Direct
Cost"
.Axes(xlCategory, xlSecondary).HasTitle = False '<=== Causing the
error!!
.Axes(xlValue, xlSecondary).HasTitle = True
.Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = "Direct Cost
Per Trade"
End With

I'm a novice with VBA and have never used code and charts before so have no
idea why this is happening.

The chart is a line graph with both Y Value axes required - one for each
line ('series').
 
Reply With Quote
 
 
 
 
=?Utf-8?B?ZXdhbjcyNzk=?=
Guest
Posts: n/a
 
      5th Sep 2007
The error was with the order in which the chart type was identified. Solution:

Charts.Add

ActiveChart.SetSourceData Source:=Sheets("Gas").Range(FirstMonth,
LastMonth.Offset(0, 2)), PlotBy:=xlColumns
ActiveChart.SeriesCollection(1).Name = "=""Total Direct Cost"""
ActiveChart.SeriesCollection(2).Name = "=""Direct Cost Per Trade"""
ActiveChart.Location Where:=xlLocationAsObject, Name:="Gas Charts"
ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:="Lines on 2
Axes" '<= after chart has data, not after 'Charts.Add'

With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Financials"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Month"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Total Direct
Cost"
.Axes(xlCategory, xlSecondary).HasTitle = False
.Axes(xlValue, xlSecondary).HasTitle = True
.Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = "Direct Cost
Per Trade"
End With

"ewan7279" wrote:

> Hi all,
>
> I ensounter a runtime error 1004 'Method 'Axes' of object '_Chart' failed'
> when I run this code (that I recorded):
>
> Charts.Add
> ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:="Lines on 2
> Axes"
> ActiveChart.SetSourceData Source:=Sheets("Gas").Range(FirstMonth,
> LastMonth.Offset(0, 2)), PlotBy:=xlColumns
> ActiveChart.SeriesCollection(1).Name = "=""Direct Cost Per Trade"""
> ActiveChart.SeriesCollection(2).Name = "=""Total Direct Cost"""
> ActiveChart.Location Where:=xlLocationAsObject, Name:="Gas Charts"
> With ActiveChart
> .HasTitle = True
> .ChartTitle.Characters.Text = "Financials"
> .Axes(xlCategory, xlPrimary).HasTitle = True
> .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Month"
> .Axes(xlValue, xlPrimary).HasTitle = True
> .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Total Direct
> Cost"
> .Axes(xlCategory, xlSecondary).HasTitle = False '<=== Causing the
> error!!
> .Axes(xlValue, xlSecondary).HasTitle = True
> .Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = "Direct Cost
> Per Trade"
> End With
>
> I'm a novice with VBA and have never used code and charts before so have no
> idea why this is happening.
>
> The chart is a line graph with both Y Value axes required - one for each
> line ('series').

 
Reply With Quote
 
Jon Peltier
Guest
Posts: n/a
 
      5th Sep 2007
The macro recorder is pretty good, but it's only human.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"ewan7279" <(E-Mail Removed)> wrote in message
news:A74ADD71-ADBF-489C-B809-(E-Mail Removed)...
> The error was with the order in which the chart type was identified.
> Solution:
>
> Charts.Add
>
> ActiveChart.SetSourceData Source:=Sheets("Gas").Range(FirstMonth,
> LastMonth.Offset(0, 2)), PlotBy:=xlColumns
> ActiveChart.SeriesCollection(1).Name = "=""Total Direct Cost"""
> ActiveChart.SeriesCollection(2).Name = "=""Direct Cost Per Trade"""
> ActiveChart.Location Where:=xlLocationAsObject, Name:="Gas Charts"
> ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:="Lines on 2
> Axes" '<= after chart has data, not after 'Charts.Add'
>
> With ActiveChart
> .HasTitle = True
> .ChartTitle.Characters.Text = "Financials"
> .Axes(xlCategory, xlPrimary).HasTitle = True
> .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Month"
> .Axes(xlValue, xlPrimary).HasTitle = True
> .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Total Direct
> Cost"
> .Axes(xlCategory, xlSecondary).HasTitle = False
> .Axes(xlValue, xlSecondary).HasTitle = True
> .Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = "Direct
> Cost
> Per Trade"
> End With
>
> "ewan7279" wrote:
>
>> Hi all,
>>
>> I ensounter a runtime error 1004 'Method 'Axes' of object '_Chart'
>> failed'
>> when I run this code (that I recorded):
>>
>> Charts.Add
>> ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:="Lines on
>> 2
>> Axes"
>> ActiveChart.SetSourceData Source:=Sheets("Gas").Range(FirstMonth,
>> LastMonth.Offset(0, 2)), PlotBy:=xlColumns
>> ActiveChart.SeriesCollection(1).Name = "=""Direct Cost Per Trade"""
>> ActiveChart.SeriesCollection(2).Name = "=""Total Direct Cost"""
>> ActiveChart.Location Where:=xlLocationAsObject, Name:="Gas Charts"
>> With ActiveChart
>> .HasTitle = True
>> .ChartTitle.Characters.Text = "Financials"
>> .Axes(xlCategory, xlPrimary).HasTitle = True
>> .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Month"
>> .Axes(xlValue, xlPrimary).HasTitle = True
>> .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Total
>> Direct
>> Cost"
>> .Axes(xlCategory, xlSecondary).HasTitle = False '<=== Causing the
>> error!!
>> .Axes(xlValue, xlSecondary).HasTitle = True
>> .Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = "Direct
>> Cost
>> Per Trade"
>> End With
>>
>> I'm a novice with VBA and have never used code and charts before so have
>> no
>> idea why this is happening.
>>
>> The chart is a line graph with both Y Value axes required - one for each
>> line ('series').



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 error "some chart types cannot be combined with other chart types. Select a different chart types" roadsidetree Microsoft Excel Charting 17 12th May 2010 06:51 PM
Cannot combine chart type error with only one chart. Kermit Microsoft Excel Charting 8 5th Feb 2009 06:25 PM
Export a chart in a GIF file. Run-time error '1004': Application-defined or object-defined error; cschiffers@gmail.com Microsoft Excel Programming 5 17th Sep 2007 12:48 PM
Chart Error when using Chart Line - Column on 2 Axes in vba code =?Utf-8?B?Sm9obg==?= Microsoft Excel Programming 2 3rd Aug 2007 01:42 PM
Cannot Activate Chart Area in Chart. Chart Object Failed ahperez@gmail.com Microsoft Excel Programming 2 8th Aug 2006 02:38 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:02 PM.