View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
John John is offline
external usenet poster
 
Posts: 2,069
Default Program a combination chart using VBA

I use excel 2003 and when I try to use the macro recoder to create a custom
chart type of "Line - Column on 2 Axes" the recoder creates the following
code and an example of the data is below the code. The chart that is creaded
the first time when recording the macro is perfect.

However when I try to excute the macro I either receive an error message
runtime error 1004, "Methods axes of object - chart failed when I name the
axes of the Series or

I simply have a column chart and not a combination chart.

What I am trying to do is have a single chart that shows staff in column and
Volumn in line by time of day. I can make it work perfect by hand but I am
unable to write a VBA routine that will accomplish the same thing again. VBA
acts like it doesn't reconize the Chart Type.

Please help and Thanks in advance

'Macro Code
Charts.Add
ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:= _
"Line - Column on 2 Axes"
ActiveChart.SetSourceData
Source:=Sheets("Data").Range("B37:D61"),PlotBy:= _ xlColumns
ActiveChart.Location Whe=xlLocationAsObject, Name:="Data"
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = False
End With
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
Selection.Position = xlBottom
With Selection.Interior
.ColorIndex = 36
.Pattern = 1
End With
End Sub

Spread Sheet Data
Col B Col C Col D
Row 37 Hours Staff Volumn
Row 38 0:00 2 52280
Row 39 1:00 2 52280
Row 40 2:00 2 52280
Row 41 3:00 1 52280
Row 42 4:00 0 52280
Row 43 5:00 0 52280
Row 44 6:00 0 52280
Row 45 7:00 0 52280
Row 46 8:00 0 95280
Row 47 9:00 0 58380
Row 48 10:00 0 52380
Row 49 11:00 0 58980
Row 50 12:00 4 81280
Row 51 13:00 4 117080
Row 52 14:00 4 70880
Row 53 15:00 3 96100
Row 54 16:00 4 91900
Row 55 17:00 4 27600
Row 56 18:00 3 62300
Row 57 19:00 2 44900
Row 58 20:00 2 22700
Row 59 21:00 2 9000
Row 60 22:00 2 0
Row 61 23:00 2 0