View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Jon Peltier Jon Peltier is offline
external usenet poster
 
Posts: 6,582
Default iterate through chart series collection

A series has no Count property, but the SeriesCollection does. You need
either

Dim xSer As Series
For Each xSer In aChart.SeriesCollection
' blah
Next

which I suggested, or

Dim i As Integer
For i = 1 to aChart.SeriesCollection.Count
' blah
Next

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


"Robert H" wrote in message
oups.com...
Thanks Vergel.

at this line: For i = 1 To xSer.Count
I get "object doesn't support this property or method


On Feb 23, 5:37 pm, Vergel Adriano
wrote:
I believe you can account for the number of series being dynamic by doing
something like this:

Dim xSer As SeriesCollection
Dim i As Integer
For Each xSer In aChart
For i = 1 To xSer.Count
xSer.Item(i).XValues = Range("code")
Next i
Next

"Robert H" wrote:
sorry to be bugging the group so mych about charts but Im getting my
butt kicked. The new problem is this:


Building a column chart and needing to add the series x axis labels
which are set in VBA with
..SeriesCollection(#).XValues for each series. I need to set them all
to a named range(the same range of cells)
Im working with: some code removed for clearity)


Dim aChart As Chart
Dim shtNm As String
shtNm = ActiveSheet.Name


Set aChart = Charts.Add
Set aChart = aChart.Location(Whe=xlLocationAsObject,
Name:=shtNm)


Dim xSer As SeriesCollection
For Each xSer In aChart
.XValues = Range("code")
Next


I can set each series individuly but I need to set them as one because
the number of series is variable and can change each time the macro
runs. The named range "CODE" is always the correct size to match the
number in the series.


is there a way to make this work?
Thanks
Robert