Custom chart types; Recorded macro acts strange

U

ucanalways

I turned on the macro recorder and created a "Line on 2 Axes" chart.
The recorded macro is given below.

I ran the recorded macro but I got a different output (I think the
output was a column chart instead of "Line on 2 Axes" chart)

Why is it so? Usually macro-recorder's code works perfect. Should I
need to turn-on any references or add-ins? Someone who has a solution
for this, please clarify. Thanks

Sub Macro1()

Charts.Add
ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:= _
"Lines on 2 Axes"
ActiveChart.SetSourceData
Source:=Sheets("Sheet1").Range("A:A,C:C,D:D"), _
PlotBy:=xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
With ActiveChart
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
.Axes(xlCategory, xlSecondary).HasTitle = False
.Axes(xlValue, xlSecondary).HasTitle = False
End With

End Sub
 
J

Jon Peltier

Usually macro-recorder's code works perfect.

Not on planet Earth. Usually it gives you the right idea, but it needs
tweaking.

In any case, your recorded macro defined the chart type before there was any
data, so when you added data, the default chart type was applied. Switch the
ApplyCustomType line to after the SetSourceData line.

- Jon
 
T

Thulasiram

Not on planet Earth. Usually it gives you the right idea, but it needs
tweaking.

In any case, your recorded macro defined the chart type before there was any
data, so when you added data, the default chart type was applied. Switch the
ApplyCustomType line to after the SetSourceData line.

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

Jon, this is the first time I am facing the weird behavior of macros.
Btw, your trick works. Thanks.
 
U

ucanalways

Not on planet Earth. Usually it gives you the right idea, but it needs
tweaking.

In any case, your recorded macro defined the chart type before there was any
data, so when you added data, the default chart type was applied. Switch the
ApplyCustomType line to after the SetSourceData line.

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

Jon, Thanks. It works.
 
U

ucanalways

Not on planet Earth. Usually it gives you the right idea, but it needs
tweaking.

In any case, your recorded macro defined the chart type before there was any
data, so when you added data, the default chart type was applied. Switch the
ApplyCustomType line to after the SetSourceData line.

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

Jon, Thanks. It works.
 

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