G
Gleam
I would like a macro to create a chart with twin columns but different axes.
I have recorded a macro using "Line - Column on 2 Axes" which is the closest
towhat Iwant but when I run it, the code fails. (Excel 2003)
Here is the code with a comment at the point where it falls over:
Sub ChartTest()
Dim sel As Range, sel2 As Range
[a1] = "Causes"
[b1] = "Roll Changes"
[c1] = "Strip Breaks"
[d1] = "Cobbles"
[a2] = "Time Lost"
[b2] = 220
[c2] = 64
[d2] = 5
[a3] = "Occurences"
[b3] = 12
[c3] = 4
[d3] = 1
Columns("A").EntireColumn.AutoFit
Set sel = Range("A12")
Set sel2 = Range("A33")
' had to add Activeworkbook to next line
ActiveWorkbook.Charts.Add
ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:= _
"Line - Column on 2 Axes"
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A13"),
PlotBy:= _
xlRows
ActiveChart.Location Where:=xlLocationAsObject, name:="Sheet1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Delay Causes"
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Time Lost
(min)"
' fails on next line
.Axes(xlCategory, xlSecondary).HasTitle = False ' fails here
.Axes(xlValue, xlSecondary).HasTitle = True
.Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = "Occurences"
End With
ActiveChart.HasLegend = False
ActiveChart.HasDataTable = True
ActiveChart.DataTable.ShowLegendKey = True
ActiveChart.Axes(xlValue, xlSecondary).Select
With ActiveChart.Axes(xlValue, xlSecondary)
.MinimumScaleIsAuto = True
.MaximumScale = .MaximumScale * 2
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
End Sub
I have recorded a macro using "Line - Column on 2 Axes" which is the closest
towhat Iwant but when I run it, the code fails. (Excel 2003)
Here is the code with a comment at the point where it falls over:
Sub ChartTest()
Dim sel As Range, sel2 As Range
[a1] = "Causes"
[b1] = "Roll Changes"
[c1] = "Strip Breaks"
[d1] = "Cobbles"
[a2] = "Time Lost"
[b2] = 220
[c2] = 64
[d2] = 5
[a3] = "Occurences"
[b3] = 12
[c3] = 4
[d3] = 1
Columns("A").EntireColumn.AutoFit
Set sel = Range("A12")
Set sel2 = Range("A33")
' had to add Activeworkbook to next line
ActiveWorkbook.Charts.Add
ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:= _
"Line - Column on 2 Axes"
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A13"),
PlotBy:= _
xlRows
ActiveChart.Location Where:=xlLocationAsObject, name:="Sheet1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Delay Causes"
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Time Lost
(min)"
' fails on next line
.Axes(xlCategory, xlSecondary).HasTitle = False ' fails here
.Axes(xlValue, xlSecondary).HasTitle = True
.Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = "Occurences"
End With
ActiveChart.HasLegend = False
ActiveChart.HasDataTable = True
ActiveChart.DataTable.ShowLegendKey = True
ActiveChart.Axes(xlValue, xlSecondary).Select
With ActiveChart.Axes(xlValue, xlSecondary)
.MinimumScaleIsAuto = True
.MaximumScale = .MaximumScale * 2
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
End Sub