Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA for charting


Hi all,
I am very new to VBA.(but trying)

I have the following code to produce a chart.

Sub AddChartObject()
Dim myChtObj As ChartObject
'
Set myChtObj = ActiveSheet.ChartObjects.Add _
(Left:=20, Width:=700, Top:=120, Height:=225)
myChtObj.Chart.SetSourceData
Source:=Sheets("Sheet1").Range("a3:a6"), _
PlotBy:=xlRows
myChtObj.Chart.ChartType = xlColumnStacked

End Sub

I needed the chart to show the data in each column stacked ontop of
each other (just that column) and worked out to put the plotby rows
command in. That worked great for the first series.

I now have the following code to add a new series,

Sub AddNewSeriesAL0100()
With ActiveChart.SeriesCollection.NewSeries
..Values = ActiveSheet.Range("b3:b6")
End With
End Sub

but when I do it does not stack the data ontop of each other in the
chart, it puts them side by side. I have tried putting the plotby rows
command in but it doesn't seem to work for the new series.

Can anyone help me out to be able to stack any new series.

Thanks for any assistance.


--
greg7468


------------------------------------------------------------------------
greg7468's Profile: http://www.excelforum.com/member.php...fo&userid=9031
View this thread: http://www.excelforum.com/showthread...hreadid=384467

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default VBA for charting

You need to repeat this line when you add a second series:

ActiveChart.ChartType = xlColumnStacked

Excel somehow forgets you had a stacked chart and converts to the
default clustered variety.

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


greg7468 wrote:

Hi all,
I am very new to VBA.(but trying)

I have the following code to produce a chart.

Sub AddChartObject()
Dim myChtObj As ChartObject
'
Set myChtObj = ActiveSheet.ChartObjects.Add _
(Left:=20, Width:=700, Top:=120, Height:=225)
myChtObj.Chart.SetSourceData
Source:=Sheets("Sheet1").Range("a3:a6"), _
PlotBy:=xlRows
myChtObj.Chart.ChartType = xlColumnStacked

End Sub

I needed the chart to show the data in each column stacked ontop of
each other (just that column) and worked out to put the plotby rows
command in. That worked great for the first series.

I now have the following code to add a new series,

Sub AddNewSeriesAL0100()
With ActiveChart.SeriesCollection.NewSeries
Values = ActiveSheet.Range("b3:b6")
End With
End Sub

but when I do it does not stack the data ontop of each other in the
chart, it puts them side by side. I have tried putting the plotby rows
command in but it doesn't seem to work for the new series.

Can anyone help me out to be able to stack any new series.

Thanks for any assistance.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA for charting


Thanks for the reply Jon,

however even with the extra code inserted it still does not stack them
for the second series.

Any other ideas welcome.


--
greg7468


------------------------------------------------------------------------
greg7468's Profile: http://www.excelforum.com/member.php...fo&userid=9031
View this thread: http://www.excelforum.com/showthread...hreadid=384467

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default VBA for charting

Okay, now I'm looking more carefully at your first procedure. When you
run this procedure, notice the legend. You have created four series, not
just one. What you want to do in your second procedure is extend each
series, not add a new series. This should do it:

Sub ExtendSeriesCollection()
ActiveChart.SeriesCollection.Extend _
Source:=ActiveSheet.Range("B3:B6"), Rowcol:=xlRows
End Sub

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


greg7468 wrote:

Thanks for the reply Jon,

however even with the extra code inserted it still does not stack them
for the second series.

Any other ideas welcome.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA for charting


Thank you Jon,

just what I wanted

--
greg746

-----------------------------------------------------------------------
greg7468's Profile: http://www.excelforum.com/member.php...nfo&userid=903
View this thread: http://www.excelforum.com/showthread.php?threadid=38446



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Charting help... oldsquid Charts and Charting in Excel 3 August 24th 07 01:29 AM
Charting par3 Excel Discussion (Misc queries) 2 August 1st 07 05:16 PM
Boy do I need your help with charting! Marty Charts and Charting in Excel 2 May 12th 05 02:28 PM
Custom charting - Stacked charting with a line Randy Lefferts Charts and Charting in Excel 3 March 3rd 05 03:10 AM
Looking for help with MFC and Charting Robert King Excel Programming 0 September 25th 03 04:07 PM


All times are GMT +1. The time now is 12:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"