Chart Creation using VBA

J

Jimmy

I recorded a chart creation event macro and then tried to paste it into
my project. It always fails on line #15 (see below). What am I doing
wrong? And what shoud I do to fix it?
Thank you,
jimmy




1 Sub Chartwork1()
2 Charts.Add
3 ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:= _
4 "Lines on 2 Axes"
5 ActiveChart.SetSourceData Source:=Sheets("Chart").Range(topLeft &
":" & bottomRight), PlotBy:= _
6 xlRows
7 ActiveChart.Location Where:=xlLocationAsObject, Name:="Chart"
8 With ActiveChart
9 .HasTitle = True
10 .ChartTitle.Characters.Text = "Bid/Quote Success Rate"
11 .Axes(xlCategory, xlPrimary).HasTitle = False
12 .Axes(xlValue, xlPrimary).HasTitle = True
13 .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = _
14 "# of Bids/Quotes Received"
15 ' .Axes(xlCategory, xlSecondary).HasTitle = False
16 ' .Axes(xlValue, xlSecondary).HasTitle = True
17 ' .Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = _
18 "% Submitted of Received or % Won to Date of
Submitted/Received"
19 End With
20 ActiveChart.HasLegend = False
21 ActiveChart.HasDataTable = True
22 ActiveChart.DataTable.ShowLegendKey = True
23 ActiveChart.Axes(xlValue).Select
24 With ActiveChart.Axes(xlValue)
25 .MinimumScale = 1000
26 .MaximumScale = 5000
27 .MinorUnit = 1000
28 .MajorUnit = 1000
29 .Crosses = xlCustom
30 .CrossesAt = 1000
31 .ReversePlotOrder = False
32 .ScaleType = xlLinear
33 .DisplayUnit = xlNone
34 End With
35 ActiveChart.Axes(xlValue, xlSecondary).Select
36 With ActiveChart.Axes(xlValue, xlSecondary)
37 .MinimumScaleIsAuto = True
38 .MaximumScale = 1
39 .MinorUnit = 0.2
40 .MajorUnit = 0.2
41 .Crosses = xlAutomatic
42 .ReversePlotOrder = False
43 .ScaleType = xlLinear
44 .DisplayUnit = xlNone
45 End With
46 ActiveChart.SeriesCollection(1).Select
47 With Selection.Border
48 .ColorIndex = 1
49 .Weight = xlThick
50 .LineStyle = xlContinuous
51 End With
52 With Selection
53 .MarkerBackgroundColorIndex = xlAutomatic
54 .MarkerForegroundColorIndex = xlAutomatic
55 .MarkerStyle = xlNone
56 .Smooth = True
57 .MarkerSize = 9
58 .Shadow = False
59 End With
60 ActiveChart.SeriesCollection(1).AxisGroup = 2
61 End Sub
 
J

Jimmy

Also, the error message reads
"Run time error '1004'
Method 'Axes' of Object 'Chart_Chart' failed."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top