PC Review


Reply
Thread Tools Rate Thread

Custom chart types; Recorded macro acts strange

 
 
ucanalways@gmail.com
Guest
Posts: n/a
 
      23rd Oct 2007
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"), _
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

 
Reply With Quote
 
 
 
 
Jon Peltier
Guest
Posts: n/a
 
      23rd Oct 2007
> 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
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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"), _
> 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
>



 
Reply With Quote
 
Thulasiram
Guest
Posts: n/a
 
      23rd Oct 2007
On Oct 22, 9:23 pm, "Jon Peltier" <jonxlmv...@SPAMpeltiertech.com>
wrote:
> > 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
> -------
> Jon Peltier, Microsoft Excel MVP
> Tutorials and Custom Solutions
> Peltier Technical Services, Inc. -http://PeltierTech.com
> _______
>
> <ucanalw...@gmail.com> wrote in message
>
> news:(E-Mail Removed)...
>
> >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"), _
> > 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


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

 
Reply With Quote
 
ucanalways@gmail.com
Guest
Posts: n/a
 
      23rd Oct 2007
On Oct 22, 9:23 pm, "Jon Peltier" <jonxlmv...@SPAMpeltiertech.com>
wrote:
> > 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
> -------
> Jon Peltier, Microsoft Excel MVP
> Tutorials and Custom Solutions
> Peltier Technical Services, Inc. -http://PeltierTech.com
> _______
>
> <ucanalw...@gmail.com> wrote in message
>
> news:(E-Mail Removed)...
>
> >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"), _
> > 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


Jon, Thanks. It works.

 
Reply With Quote
 
ucanalways@gmail.com
Guest
Posts: n/a
 
      23rd Oct 2007
On Oct 22, 9:23 pm, "Jon Peltier" <jonxlmv...@SPAMpeltiertech.com>
wrote:
> > 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
> -------
> Jon Peltier, Microsoft Excel MVP
> Tutorials and Custom Solutions
> Peltier Technical Services, Inc. -http://PeltierTech.com
> _______
>
> <ucanalw...@gmail.com> wrote in message
>
> news:(E-Mail Removed)...
>
> >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"), _
> > 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


Jon, Thanks. It works.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2003 is missing Built-In Custom Chart Types in Chart Wizard Julius Microsoft Excel Programming 2 6th Mar 2009 04:55 PM
Excel 2003 is missing Built-In Custom Chart Types in Chart Wizard Julius Microsoft Excel Charting 2 6th Mar 2009 04:43 PM
Excel 2003 is missing Built-In Custom Chart Types in Chart Wizard Julius Microsoft Excel Setup 1 6th Mar 2009 01:57 AM
Excel 2003 is missing Built-In Custom Chart Types in Chart Wizard Julius Microsoft Excel Programming 0 6th Mar 2009 01:21 AM
recorded macro error/Chart myleo727 Microsoft Excel New Users 0 13th Aug 2008 02:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:51 AM.