PC Review


Reply
Thread Tools Rate Thread

add new chart in 2007

 
 
=?Utf-8?B?Sk5X?=
Guest
Posts: n/a
 
      12th Nov 2007
The code below is from xl2003. This created a nice chart. There were 5
values in one column cluster. The headers were on row 5 the values on row 8.

Is this possibe to recreate? I've looked through Help, and the object
browser to no avail. The chart looks different, it won't plot by columns,
and I can't seem to move it with VBA. I've tried recording the changes,
chartobject, chartobjects, chartwizard, and more I can't remember.

I feel I am missing something simple.

Any thoughts are appreciated.

With ActiveSheet.Shapes.AddChart(ChartType:=xlColumnClustered, _
Left:=5, _
Top:=Range("B5").End(xlDown).Offset(2, 0).Top, _
Width:=Range(Range("A5"), Range("B5").End(xlToRight)).Width
- 10, _
Height:=Range("B5").End(xlDown).Offset(23, 0).Top =
Range("B5").End(xlDown).Offset(2, 0).Top)
.Chart.SetSourceData
Source:=Union(ActiveSheet.Range(Range("B4"),
Range("C4").End(xlToRight).Offset(0, -1)), ActiveSheet.Range(Range("B8"),
Range("B8").End(xlToRight).Offset(0, -1))), PlotBy:=xlColumns
End With
 
Reply With Quote
 
 
 
 
Jon Peltier
Guest
Posts: n/a
 
      14th Nov 2007
ActiveSheet.Shapes.AddChart() is new in 2007. I presume your citation of
Excel 2003 is a typo.

I have not used this new syntax enough to have tripped over all of the
possible problems with it. You could go back to Excel 2003 syntax, which is
still valid:

With ActiveSheet.ChartObjects.Add({left, top, width, height}).Chart
.SetSourceData Source:={range}, PlotBy:=xlColumns
.etc
End With

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

"JNW" <(E-Mail Removed)> wrote in message
news:B317834F-68C2-4918-AB4B-(E-Mail Removed)...
> The code below is from xl2003. This created a nice chart. There were 5
> values in one column cluster. The headers were on row 5 the values on row
> 8.
>
> Is this possibe to recreate? I've looked through Help, and the object
> browser to no avail. The chart looks different, it won't plot by columns,
> and I can't seem to move it with VBA. I've tried recording the changes,
> chartobject, chartobjects, chartwizard, and more I can't remember.
>
> I feel I am missing something simple.
>
> Any thoughts are appreciated.
>
> With ActiveSheet.Shapes.AddChart(ChartType:=xlColumnClustered, _
> Left:=5, _
> Top:=Range("B5").End(xlDown).Offset(2, 0).Top, _
> Width:=Range(Range("A5"), Range("B5").End(xlToRight)).Width
> - 10, _
> Height:=Range("B5").End(xlDown).Offset(23, 0).Top =
> Range("B5").End(xlDown).Offset(2, 0).Top)
> .Chart.SetSourceData
> Source:=Union(ActiveSheet.Range(Range("B4"),
> Range("C4").End(xlToRight).Offset(0, -1)), ActiveSheet.Range(Range("B8"),
> Range("B8").End(xlToRight).Offset(0, -1))), PlotBy:=xlColumns
> End With



 
Reply With Quote
 
=?Utf-8?B?Sk5X?=
Guest
Posts: n/a
 
      14th Nov 2007
Jon-

You're right. I posted my attempt at trying to make it work. The code for
2003 (activesheet.chartobjects.add) doesn't create charts in 2007. That's
why I'm at this crossroads. A colleague of mine did find a KB site yesterday
that may offer a solution. I haven't tried it yet but will post back with my
results.


http://support.microsoft.com/kb/937620/en-us


"Jon Peltier" wrote:

> ActiveSheet.Shapes.AddChart() is new in 2007. I presume your citation of
> Excel 2003 is a typo.
>
> I have not used this new syntax enough to have tripped over all of the
> possible problems with it. You could go back to Excel 2003 syntax, which is
> still valid:
>
> With ActiveSheet.ChartObjects.Add({left, top, width, height}).Chart
> .SetSourceData Source:={range}, PlotBy:=xlColumns
> .etc
> End With
>
> - Jon
> -------
> Jon Peltier, Microsoft Excel MVP
> Tutorials and Custom Solutions
> Peltier Technical Services, Inc. - http://PeltierTech.com
> _______
>
> "JNW" <(E-Mail Removed)> wrote in message
> news:B317834F-68C2-4918-AB4B-(E-Mail Removed)...
> > The code below is from xl2003. This created a nice chart. There were 5
> > values in one column cluster. The headers were on row 5 the values on row
> > 8.
> >
> > Is this possibe to recreate? I've looked through Help, and the object
> > browser to no avail. The chart looks different, it won't plot by columns,
> > and I can't seem to move it with VBA. I've tried recording the changes,
> > chartobject, chartobjects, chartwizard, and more I can't remember.
> >
> > I feel I am missing something simple.
> >
> > Any thoughts are appreciated.
> >
> > With ActiveSheet.Shapes.AddChart(ChartType:=xlColumnClustered, _
> > Left:=5, _
> > Top:=Range("B5").End(xlDown).Offset(2, 0).Top, _
> > Width:=Range(Range("A5"), Range("B5").End(xlToRight)).Width
> > - 10, _
> > Height:=Range("B5").End(xlDown).Offset(23, 0).Top =
> > Range("B5").End(xlDown).Offset(2, 0).Top)
> > .Chart.SetSourceData
> > Source:=Union(ActiveSheet.Range(Range("B4"),
> > Range("C4").End(xlToRight).Offset(0, -1)), ActiveSheet.Range(Range("B8"),
> > Range("B8").End(xlToRight).Offset(0, -1))), PlotBy:=xlColumns
> > End With

>
>
>

 
Reply With Quote
 
Jon Peltier
Guest
Posts: n/a
 
      14th Nov 2007
> The code for 2003 (activesheet.chartobjects.add) doesn't create charts in
> 2007.


Except that it does create charts in 2007. The MSKB article you cited has no
code for creating charts, only for formatting chart elements.

Post the code that doesn't work, and describe what "doesn't work" means:
what's the failure mode, what's the error message, etc.?

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


"JNW" <(E-Mail Removed)> wrote in message
news:B1213533-F6B2-4A45-82A8-(E-Mail Removed)...
> Jon-
>
> You're right. I posted my attempt at trying to make it work. The code
> for
> 2003 (activesheet.chartobjects.add) doesn't create charts in 2007. That's
> why I'm at this crossroads. A colleague of mine did find a KB site
> yesterday
> that may offer a solution. I haven't tried it yet but will post back with
> my
> results.
>
>
> http://support.microsoft.com/kb/937620/en-us
>
>
> "Jon Peltier" wrote:
>
>> ActiveSheet.Shapes.AddChart() is new in 2007. I presume your citation of
>> Excel 2003 is a typo.
>>
>> I have not used this new syntax enough to have tripped over all of the
>> possible problems with it. You could go back to Excel 2003 syntax, which
>> is
>> still valid:
>>
>> With ActiveSheet.ChartObjects.Add({left, top, width, height}).Chart
>> .SetSourceData Source:={range}, PlotBy:=xlColumns
>> .etc
>> End With
>>
>> - Jon
>> -------
>> Jon Peltier, Microsoft Excel MVP
>> Tutorials and Custom Solutions
>> Peltier Technical Services, Inc. - http://PeltierTech.com
>> _______
>>
>> "JNW" <(E-Mail Removed)> wrote in message
>> news:B317834F-68C2-4918-AB4B-(E-Mail Removed)...
>> > The code below is from xl2003. This created a nice chart. There were
>> > 5
>> > values in one column cluster. The headers were on row 5 the values on
>> > row
>> > 8.
>> >
>> > Is this possibe to recreate? I've looked through Help, and the object
>> > browser to no avail. The chart looks different, it won't plot by
>> > columns,
>> > and I can't seem to move it with VBA. I've tried recording the
>> > changes,
>> > chartobject, chartobjects, chartwizard, and more I can't remember.
>> >
>> > I feel I am missing something simple.
>> >
>> > Any thoughts are appreciated.
>> >
>> > With ActiveSheet.Shapes.AddChart(ChartType:=xlColumnClustered, _
>> > Left:=5, _
>> > Top:=Range("B5").End(xlDown).Offset(2, 0).Top, _
>> > Width:=Range(Range("A5"),
>> > Range("B5").End(xlToRight)).Width
>> > - 10, _
>> > Height:=Range("B5").End(xlDown).Offset(23, 0).Top =
>> > Range("B5").End(xlDown).Offset(2, 0).Top)
>> > .Chart.SetSourceData
>> > Source:=Union(ActiveSheet.Range(Range("B4"),
>> > Range("C4").End(xlToRight).Offset(0, -1)),
>> > ActiveSheet.Range(Range("B8"),
>> > Range("B8").End(xlToRight).Offset(0, -1))), PlotBy:=xlColumns
>> > End With

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?Sk5X?=
Guest
Posts: n/a
 
      14th Nov 2007
Here is the code that created a chart in xl2003. As I said before,
ActiveSheet.ChartObjects.Add does not create a chart in xl2007 (That's been
my experience using the code below, but maybe I've got the syntax wrong). I
posted the MSKB website because I found out how to create a chart (using
ActiveSheet.Shapes.AddChart() from Original post) and was glad to find
something to allow me to move it to the desired location.

thanks for taking a look.

With ActiveSheet.ChartObjects.Add _
(Left:=5, _
Top:=Range("B5").End(xlDown).Offset(2, 0).Top, _
Width:=Range(Range("A5"), Range("B5").End(xlToRight)).Width -
10, _
Height:=Range("B5").End(xlDown).Offset(23, 0).Top -
Range("B5").End(xlDown).Offset(2, 0).Top)
.Chart.SetSourceData Source:=Union(ActiveSheet.Range(Range("B4"),
Range("C4").End(xlToRight).Offset(0, -1)), ActiveSheet.Range(Range("B8"),
Range("B8").End(xlToRight).Offset(0, -1))), PlotBy:=xlColumns
.Chart.ChartType = xlColumnClustered
End With


"Jon Peltier" wrote:

> > The code for 2003 (activesheet.chartobjects.add) doesn't create charts in
> > 2007.

>
> Except that it does create charts in 2007. The MSKB article you cited has no
> code for creating charts, only for formatting chart elements.
>
> Post the code that doesn't work, and describe what "doesn't work" means:
> what's the failure mode, what's the error message, etc.?
>
> - Jon
> -------
> Jon Peltier, Microsoft Excel MVP
> Tutorials and Custom Solutions
> Peltier Technical Services, Inc. - http://PeltierTech.com
> _______
>
>
> "JNW" <(E-Mail Removed)> wrote in message
> news:B1213533-F6B2-4A45-82A8-(E-Mail Removed)...
> > Jon-
> >
> > You're right. I posted my attempt at trying to make it work. The code
> > for
> > 2003 (activesheet.chartobjects.add) doesn't create charts in 2007. That's
> > why I'm at this crossroads. A colleague of mine did find a KB site
> > yesterday
> > that may offer a solution. I haven't tried it yet but will post back with
> > my
> > results.
> >
> >
> > http://support.microsoft.com/kb/937620/en-us
> >
> >
> > "Jon Peltier" wrote:
> >
> >> ActiveSheet.Shapes.AddChart() is new in 2007. I presume your citation of
> >> Excel 2003 is a typo.
> >>
> >> I have not used this new syntax enough to have tripped over all of the
> >> possible problems with it. You could go back to Excel 2003 syntax, which
> >> is
> >> still valid:
> >>
> >> With ActiveSheet.ChartObjects.Add({left, top, width, height}).Chart
> >> .SetSourceData Source:={range}, PlotBy:=xlColumns
> >> .etc
> >> End With
> >>
> >> - Jon
> >> -------
> >> Jon Peltier, Microsoft Excel MVP
> >> Tutorials and Custom Solutions
> >> Peltier Technical Services, Inc. - http://PeltierTech.com
> >> _______
> >>
> >> "JNW" <(E-Mail Removed)> wrote in message
> >> news:B317834F-68C2-4918-AB4B-(E-Mail Removed)...
> >> > The code below is from xl2003. This created a nice chart. There were
> >> > 5
> >> > values in one column cluster. The headers were on row 5 the values on
> >> > row
> >> > 8.
> >> >
> >> > Is this possibe to recreate? I've looked through Help, and the object
> >> > browser to no avail. The chart looks different, it won't plot by
> >> > columns,
> >> > and I can't seem to move it with VBA. I've tried recording the
> >> > changes,
> >> > chartobject, chartobjects, chartwizard, and more I can't remember.
> >> >
> >> > I feel I am missing something simple.
> >> >
> >> > Any thoughts are appreciated.
> >> >
> >> > With ActiveSheet.Shapes.AddChart(ChartType:=xlColumnClustered, _
> >> > Left:=5, _
> >> > Top:=Range("B5").End(xlDown).Offset(2, 0).Top, _
> >> > Width:=Range(Range("A5"),
> >> > Range("B5").End(xlToRight)).Width
> >> > - 10, _
> >> > Height:=Range("B5").End(xlDown).Offset(23, 0).Top =
> >> > Range("B5").End(xlDown).Offset(2, 0).Top)
> >> > .Chart.SetSourceData
> >> > Source:=Union(ActiveSheet.Range(Range("B4"),
> >> > Range("C4").End(xlToRight).Offset(0, -1)),
> >> > ActiveSheet.Range(Range("B8"),
> >> > Range("B8").End(xlToRight).Offset(0, -1))), PlotBy:=xlColumns
> >> > End With
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Mike Middleton
Guest
Posts: n/a
 
      14th Nov 2007
JNW -

I haven't looked at your code, but you could look at mine. I gave up trying
to find VBA code that would work on both 97-2003 and 2007, so I wrote
separate sections of code for each case. The example is the free,
unprotected Better Histogram add-in, available for download from
www.treeplan.com.

- Mike Middleton
http://www.DecisionToolworks.com
Decision Analysis Add-ins for Excel


"JNW" <(E-Mail Removed)> wrote in message
news:A8E73EF1-1D3F-4B72-A9B2-(E-Mail Removed)...
> Here is the code that created a chart in xl2003. As I said before,
> ActiveSheet.ChartObjects.Add does not create a chart in xl2007 (That's
> been
> my experience using the code below, but maybe I've got the syntax wrong).
> I
> posted the MSKB website because I found out how to create a chart (using
> ActiveSheet.Shapes.AddChart() from Original post) and was glad to find
> something to allow me to move it to the desired location.
>
> thanks for taking a look.
>
> With ActiveSheet.ChartObjects.Add _
> (Left:=5, _
> Top:=Range("B5").End(xlDown).Offset(2, 0).Top, _
> Width:=Range(Range("A5"), Range("B5").End(xlToRight)).Width -
> 10, _
> Height:=Range("B5").End(xlDown).Offset(23, 0).Top -
> Range("B5").End(xlDown).Offset(2, 0).Top)
> .Chart.SetSourceData Source:=Union(ActiveSheet.Range(Range("B4"),
> Range("C4").End(xlToRight).Offset(0, -1)), ActiveSheet.Range(Range("B8"),
> Range("B8").End(xlToRight).Offset(0, -1))), PlotBy:=xlColumns
> .Chart.ChartType = xlColumnClustered
> End With
>
>
> "Jon Peltier" wrote:
>
>> > The code for 2003 (activesheet.chartobjects.add) doesn't create charts
>> > in
>> > 2007.

>>
>> Except that it does create charts in 2007. The MSKB article you cited has
>> no
>> code for creating charts, only for formatting chart elements.
>>
>> Post the code that doesn't work, and describe what "doesn't work" means:
>> what's the failure mode, what's the error message, etc.?
>>
>> - Jon
>> -------
>> Jon Peltier, Microsoft Excel MVP
>> Tutorials and Custom Solutions
>> Peltier Technical Services, Inc. - http://PeltierTech.com
>> _______
>>
>>
>> "JNW" <(E-Mail Removed)> wrote in message
>> news:B1213533-F6B2-4A45-82A8-(E-Mail Removed)...
>> > Jon-
>> >
>> > You're right. I posted my attempt at trying to make it work. The code
>> > for
>> > 2003 (activesheet.chartobjects.add) doesn't create charts in 2007.
>> > That's
>> > why I'm at this crossroads. A colleague of mine did find a KB site
>> > yesterday
>> > that may offer a solution. I haven't tried it yet but will post back
>> > with
>> > my
>> > results.
>> >
>> >
>> > http://support.microsoft.com/kb/937620/en-us
>> >
>> >
>> > "Jon Peltier" wrote:
>> >
>> >> ActiveSheet.Shapes.AddChart() is new in 2007. I presume your citation
>> >> of
>> >> Excel 2003 is a typo.
>> >>
>> >> I have not used this new syntax enough to have tripped over all of the
>> >> possible problems with it. You could go back to Excel 2003 syntax,
>> >> which
>> >> is
>> >> still valid:
>> >>
>> >> With ActiveSheet.ChartObjects.Add({left, top, width, height}).Chart
>> >> .SetSourceData Source:={range}, PlotBy:=xlColumns
>> >> .etc
>> >> End With
>> >>
>> >> - Jon
>> >> -------
>> >> Jon Peltier, Microsoft Excel MVP
>> >> Tutorials and Custom Solutions
>> >> Peltier Technical Services, Inc. - http://PeltierTech.com
>> >> _______
>> >>
>> >> "JNW" <(E-Mail Removed)> wrote in message
>> >> news:B317834F-68C2-4918-AB4B-(E-Mail Removed)...
>> >> > The code below is from xl2003. This created a nice chart. There
>> >> > were
>> >> > 5
>> >> > values in one column cluster. The headers were on row 5 the values
>> >> > on
>> >> > row
>> >> > 8.
>> >> >
>> >> > Is this possibe to recreate? I've looked through Help, and the
>> >> > object
>> >> > browser to no avail. The chart looks different, it won't plot by
>> >> > columns,
>> >> > and I can't seem to move it with VBA. I've tried recording the
>> >> > changes,
>> >> > chartobject, chartobjects, chartwizard, and more I can't remember.
>> >> >
>> >> > I feel I am missing something simple.
>> >> >
>> >> > Any thoughts are appreciated.
>> >> >
>> >> > With
>> >> > ActiveSheet.Shapes.AddChart(ChartType:=xlColumnClustered, _
>> >> > Left:=5, _
>> >> > Top:=Range("B5").End(xlDown).Offset(2, 0).Top, _
>> >> > Width:=Range(Range("A5"),
>> >> > Range("B5").End(xlToRight)).Width
>> >> > - 10, _
>> >> > Height:=Range("B5").End(xlDown).Offset(23, 0).Top =
>> >> > Range("B5").End(xlDown).Offset(2, 0).Top)
>> >> > .Chart.SetSourceData
>> >> > Source:=Union(ActiveSheet.Range(Range("B4"),
>> >> > Range("C4").End(xlToRight).Offset(0, -1)),
>> >> > ActiveSheet.Range(Range("B8"),
>> >> > Range("B8").End(xlToRight).Offset(0, -1))), PlotBy:=xlColumns
>> >> > End With
>> >>
>> >>
>> >>

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?Sk5X?=
Guest
Posts: n/a
 
      14th Nov 2007
Thanks Mike. This will be a great help. I, too, gave up on making the code
the same. I just couldn't find the controls for the charts in 2007.

"Mike Middleton" wrote:

> JNW -
>
> I haven't looked at your code, but you could look at mine. I gave up trying
> to find VBA code that would work on both 97-2003 and 2007, so I wrote
> separate sections of code for each case. The example is the free,
> unprotected Better Histogram add-in, available for download from
> www.treeplan.com.
>
> - Mike Middleton
> http://www.DecisionToolworks.com
> Decision Analysis Add-ins for Excel
>
>
> "JNW" <(E-Mail Removed)> wrote in message
> news:A8E73EF1-1D3F-4B72-A9B2-(E-Mail Removed)...
> > Here is the code that created a chart in xl2003. As I said before,
> > ActiveSheet.ChartObjects.Add does not create a chart in xl2007 (That's
> > been
> > my experience using the code below, but maybe I've got the syntax wrong).
> > I
> > posted the MSKB website because I found out how to create a chart (using
> > ActiveSheet.Shapes.AddChart() from Original post) and was glad to find
> > something to allow me to move it to the desired location.
> >
> > thanks for taking a look.
> >
> > With ActiveSheet.ChartObjects.Add _
> > (Left:=5, _
> > Top:=Range("B5").End(xlDown).Offset(2, 0).Top, _
> > Width:=Range(Range("A5"), Range("B5").End(xlToRight)).Width -
> > 10, _
> > Height:=Range("B5").End(xlDown).Offset(23, 0).Top -
> > Range("B5").End(xlDown).Offset(2, 0).Top)
> > .Chart.SetSourceData Source:=Union(ActiveSheet.Range(Range("B4"),
> > Range("C4").End(xlToRight).Offset(0, -1)), ActiveSheet.Range(Range("B8"),
> > Range("B8").End(xlToRight).Offset(0, -1))), PlotBy:=xlColumns
> > .Chart.ChartType = xlColumnClustered
> > End With
> >
> >
> > "Jon Peltier" wrote:
> >
> >> > The code for 2003 (activesheet.chartobjects.add) doesn't create charts
> >> > in
> >> > 2007.
> >>
> >> Except that it does create charts in 2007. The MSKB article you cited has
> >> no
> >> code for creating charts, only for formatting chart elements.
> >>
> >> Post the code that doesn't work, and describe what "doesn't work" means:
> >> what's the failure mode, what's the error message, etc.?
> >>
> >> - Jon
> >> -------
> >> Jon Peltier, Microsoft Excel MVP
> >> Tutorials and Custom Solutions
> >> Peltier Technical Services, Inc. - http://PeltierTech.com
> >> _______
> >>
> >>
> >> "JNW" <(E-Mail Removed)> wrote in message
> >> news:B1213533-F6B2-4A45-82A8-(E-Mail Removed)...
> >> > Jon-
> >> >
> >> > You're right. I posted my attempt at trying to make it work. The code
> >> > for
> >> > 2003 (activesheet.chartobjects.add) doesn't create charts in 2007.
> >> > That's
> >> > why I'm at this crossroads. A colleague of mine did find a KB site
> >> > yesterday
> >> > that may offer a solution. I haven't tried it yet but will post back
> >> > with
> >> > my
> >> > results.
> >> >
> >> >
> >> > http://support.microsoft.com/kb/937620/en-us
> >> >
> >> >
> >> > "Jon Peltier" wrote:
> >> >
> >> >> ActiveSheet.Shapes.AddChart() is new in 2007. I presume your citation
> >> >> of
> >> >> Excel 2003 is a typo.
> >> >>
> >> >> I have not used this new syntax enough to have tripped over all of the
> >> >> possible problems with it. You could go back to Excel 2003 syntax,
> >> >> which
> >> >> is
> >> >> still valid:
> >> >>
> >> >> With ActiveSheet.ChartObjects.Add({left, top, width, height}).Chart
> >> >> .SetSourceData Source:={range}, PlotBy:=xlColumns
> >> >> .etc
> >> >> End With
> >> >>
> >> >> - Jon
> >> >> -------
> >> >> Jon Peltier, Microsoft Excel MVP
> >> >> Tutorials and Custom Solutions
> >> >> Peltier Technical Services, Inc. - http://PeltierTech.com
> >> >> _______
> >> >>
> >> >> "JNW" <(E-Mail Removed)> wrote in message
> >> >> news:B317834F-68C2-4918-AB4B-(E-Mail Removed)...
> >> >> > The code below is from xl2003. This created a nice chart. There
> >> >> > were
> >> >> > 5
> >> >> > values in one column cluster. The headers were on row 5 the values
> >> >> > on
> >> >> > row
> >> >> > 8.
> >> >> >
> >> >> > Is this possibe to recreate? I've looked through Help, and the
> >> >> > object
> >> >> > browser to no avail. The chart looks different, it won't plot by
> >> >> > columns,
> >> >> > and I can't seem to move it with VBA. I've tried recording the
> >> >> > changes,
> >> >> > chartobject, chartobjects, chartwizard, and more I can't remember.
> >> >> >
> >> >> > I feel I am missing something simple.
> >> >> >
> >> >> > Any thoughts are appreciated.
> >> >> >
> >> >> > With
> >> >> > ActiveSheet.Shapes.AddChart(ChartType:=xlColumnClustered, _
> >> >> > Left:=5, _
> >> >> > Top:=Range("B5").End(xlDown).Offset(2, 0).Top, _
> >> >> > Width:=Range(Range("A5"),
> >> >> > Range("B5").End(xlToRight)).Width
> >> >> > - 10, _
> >> >> > Height:=Range("B5").End(xlDown).Offset(23, 0).Top =
> >> >> > Range("B5").End(xlDown).Offset(2, 0).Top)
> >> >> > .Chart.SetSourceData
> >> >> > Source:=Union(ActiveSheet.Range(Range("B4"),
> >> >> > Range("C4").End(xlToRight).Offset(0, -1)),
> >> >> > ActiveSheet.Range(Range("B8"),
> >> >> > Range("B8").End(xlToRight).Offset(0, -1))), PlotBy:=xlColumns
> >> >> > End With
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Jon Peltier
Guest
Posts: n/a
 
      15th Nov 2007
Here your procedure, leaving out the stuff inside the With/End With block:

Sub test1()
With ActiveSheet.ChartObjects.Add _
(Left:=5, Top:=Range("B5").End(xlDown).Offset(2, 0).Top, _
Width:=Range(Range("A5"), Range("B5").End(xlToRight)).Width -
10, _
Height:=Range("B5").End(xlDown).Offset(23, 0).Top -
Range("B5").End(xlDown).Offset(2, 0).Top)

End With
End Sub

test1 works fine in Excel 2003 and in 2007. However, your arguments are hard
to parse in the ChartObjects.Add statement. What if you use some variables
like dLeft, dTop, etc., compute their values first, then add the chart
object using the simpler variables?

Sub test1a()
Dim dLeft As Double, dTop As Double
Dim dWidth As Double, dHeight As Double

With ActiveSheet
dLeft = 5
dTop = .Range("B5").End(xlDown).Offset(2, 0).Top
dWidth = .Range(.Range("A5"), .Range("B5").End(xlToRight)).Width - 10
dHeight = .Range("B5").End(xlDown).Offset(23, 0).Top -
..Range("B5").End(xlDown).Offset(2, 0).Top

With .ChartObjects.Add(dLeft, dTop, dWidth, dHeight)

End With
End With
End Sub

Notice I didn't use Range("A5"), but I referenced it to the sheet as
ActiveSheet.Range("A5"). It probably doesn't matter in this case, but it's a
good habit to reference your objects as completely as practical.

Another point is that End(xlDown) goes to the bottom of the sheet in the
absence of a break in the data, and offset(2,0) tries to go farther than
that, which is why I thought the code wasn't working. I had a similar
problem with End(xlToRight) if there was no break in the data.

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


"JNW" <(E-Mail Removed)> wrote in message
news:A8E73EF1-1D3F-4B72-A9B2-(E-Mail Removed)...
> Here is the code that created a chart in xl2003. As I said before,
> ActiveSheet.ChartObjects.Add does not create a chart in xl2007 (That's
> been
> my experience using the code below, but maybe I've got the syntax wrong).
> I
> posted the MSKB website because I found out how to create a chart (using
> ActiveSheet.Shapes.AddChart() from Original post) and was glad to find
> something to allow me to move it to the desired location.
>
> thanks for taking a look.
>
> With ActiveSheet.ChartObjects.Add _
> (Left:=5, _
> Top:=Range("B5").End(xlDown).Offset(2, 0).Top, _
> Width:=Range(Range("A5"), Range("B5").End(xlToRight)).Width -
> 10, _
> Height:=Range("B5").End(xlDown).Offset(23, 0).Top -
> Range("B5").End(xlDown).Offset(2, 0).Top)
> .Chart.SetSourceData Source:=Union(ActiveSheet.Range(Range("B4"),
> Range("C4").End(xlToRight).Offset(0, -1)), ActiveSheet.Range(Range("B8"),
> Range("B8").End(xlToRight).Offset(0, -1))), PlotBy:=xlColumns
> .Chart.ChartType = xlColumnClustered
> End With
>
>
> "Jon Peltier" wrote:
>
>> > The code for 2003 (activesheet.chartobjects.add) doesn't create charts
>> > in
>> > 2007.

>>
>> Except that it does create charts in 2007. The MSKB article you cited has
>> no
>> code for creating charts, only for formatting chart elements.
>>
>> Post the code that doesn't work, and describe what "doesn't work" means:
>> what's the failure mode, what's the error message, etc.?
>>
>> - Jon
>> -------
>> Jon Peltier, Microsoft Excel MVP
>> Tutorials and Custom Solutions
>> Peltier Technical Services, Inc. - http://PeltierTech.com
>> _______
>>
>>
>> "JNW" <(E-Mail Removed)> wrote in message
>> news:B1213533-F6B2-4A45-82A8-(E-Mail Removed)...
>> > Jon-
>> >
>> > You're right. I posted my attempt at trying to make it work. The code
>> > for
>> > 2003 (activesheet.chartobjects.add) doesn't create charts in 2007.
>> > That's
>> > why I'm at this crossroads. A colleague of mine did find a KB site
>> > yesterday
>> > that may offer a solution. I haven't tried it yet but will post back
>> > with
>> > my
>> > results.
>> >
>> >
>> > http://support.microsoft.com/kb/937620/en-us
>> >
>> >
>> > "Jon Peltier" wrote:
>> >
>> >> ActiveSheet.Shapes.AddChart() is new in 2007. I presume your citation
>> >> of
>> >> Excel 2003 is a typo.
>> >>
>> >> I have not used this new syntax enough to have tripped over all of the
>> >> possible problems with it. You could go back to Excel 2003 syntax,
>> >> which
>> >> is
>> >> still valid:
>> >>
>> >> With ActiveSheet.ChartObjects.Add({left, top, width, height}).Chart
>> >> .SetSourceData Source:={range}, PlotBy:=xlColumns
>> >> .etc
>> >> End With
>> >>
>> >> - Jon
>> >> -------
>> >> Jon Peltier, Microsoft Excel MVP
>> >> Tutorials and Custom Solutions
>> >> Peltier Technical Services, Inc. - http://PeltierTech.com
>> >> _______
>> >>
>> >> "JNW" <(E-Mail Removed)> wrote in message
>> >> news:B317834F-68C2-4918-AB4B-(E-Mail Removed)...
>> >> > The code below is from xl2003. This created a nice chart. There
>> >> > were
>> >> > 5
>> >> > values in one column cluster. The headers were on row 5 the values
>> >> > on
>> >> > row
>> >> > 8.
>> >> >
>> >> > Is this possibe to recreate? I've looked through Help, and the
>> >> > object
>> >> > browser to no avail. The chart looks different, it won't plot by
>> >> > columns,
>> >> > and I can't seem to move it with VBA. I've tried recording the
>> >> > changes,
>> >> > chartobject, chartobjects, chartwizard, and more I can't remember.
>> >> >
>> >> > I feel I am missing something simple.
>> >> >
>> >> > Any thoughts are appreciated.
>> >> >
>> >> > With
>> >> > ActiveSheet.Shapes.AddChart(ChartType:=xlColumnClustered, _
>> >> > Left:=5, _
>> >> > Top:=Range("B5").End(xlDown).Offset(2, 0).Top, _
>> >> > Width:=Range(Range("A5"),
>> >> > Range("B5").End(xlToRight)).Width
>> >> > - 10, _
>> >> > Height:=Range("B5").End(xlDown).Offset(23, 0).Top =
>> >> > Range("B5").End(xlDown).Offset(2, 0).Top)
>> >> > .Chart.SetSourceData
>> >> > Source:=Union(ActiveSheet.Range(Range("B4"),
>> >> > Range("C4").End(xlToRight).Offset(0, -1)),
>> >> > ActiveSheet.Range(Range("B8"),
>> >> > Range("B8").End(xlToRight).Offset(0, -1))), PlotBy:=xlColumns
>> >> > End With
>> >>
>> >>
>> >>

>>
>>
>>



 
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
copy chart formatting and chart templates in Excel 2007 Astelix Microsoft Excel Charting 4 4th Mar 2010 04:10 AM
Excel 2007 Chart - determining the color of a chart style Shane Devenshire Microsoft Excel Charting 1 6th Feb 2010 04:09 AM
In Office 2007 can't see chart series values unless chart unprotec Carl Microsoft Excel Charting 0 28th Oct 2009 03:31 AM
Can not insert chart in Excel 2007? Chart does not work right? Janis Microsoft Excel Misc 0 18th Jun 2009 08:31 PM
Bar Chart to line chart excel 2007 RPG Microsoft Excel Charting 2 1st Aug 2008 07:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:05 AM.