#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Chart error

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 Whe=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').
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Chart error

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 Whe=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 Whe=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').

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Chart error

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" wrote in message
...
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 Whe=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 Whe=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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


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 Charts and Charting in Excel 15 June 2nd 09 10:53 AM
Cannot combine chart type error with only one chart. Kermit Charts and Charting in Excel 8 February 5th 09 06:25 PM
Error with chart millwalll Charts and Charting in Excel 2 January 10th 08 11:33 PM
Chart Error when using Chart Line - Column on 2 Axes in vba code John Excel Programming 2 August 3rd 07 01:42 PM
Log chart error Sandy Charts and Charting in Excel 3 April 28th 07 09:01 PM


All times are GMT +1. The time now is 10:20 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"