Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extra Data Set in Graph Legend

Status
Not open for further replies.

bhujanga

Programmer
Oct 18, 2007
181
US
I'm creating a bunch of graphs using a macro. Everything works exactly right except it gives me one extra data series in the legend, so if for example there are 7 real data series with actual names, there is also one called 'series8' in the legend but with no associated data. This is my code for one of the graphs:

ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLine
For i = 1 To TinctureTypes
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(i).Name = "='Product Sales'!R" & TinctureStart + i - 1 & "C7"
ActiveChart.SeriesCollection(i).Values = "='Product Sales'!R" & TinctureStart + i - 1 & "C8:R" & TinctureStart + i - 1 & "C" & 7 + NumberOfMonths
ActiveChart.SeriesCollection(1).XValues = "='Product Sales'!R" & TinctureStart + TinctureTypes & "C8:R" & TinctureStart + TinctureTypes & "C" & 7 + NumberOfMonths
Next i
ActiveChart.SetElement (msoElementChartTitleCenteredOverlay)
ActiveChart.ChartTitle.Select
Selection.Caption = "='Product Sales'!R" & TinctureStart & "C5"

The 'TinctureTypes' variable is correct, if I reduce it by one then I lose one of the data series and still get an extra one in just the legend. What should I do to fix this? Thanks.


 


What application and version please?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 


Please post some sample data from your Product Sales sheet.

I ran your code thru TinctureTypes=2 and only got 2 series.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Natural 52 126 91 46 15
Spearmint 48 123 72 19 4
Vanilla 0 0 27 58 19
Watermelon 56 113 65 48 17
Feb-11 Mar-11 Apr-11 May-11 Jun-11

 


OK. You realize you have given very little info, in order for ANYONE to provide cogent guidance!

So i figured, based on your VBA code, that the sample you posted belongs in g1:l5.

Using the following parameters...
Code:
Sub test()
    Dim TinctureTypes As Integer, TinctureStart As Long, NumberOfMonths As Integer, i As Integer[b]
    TinctureTypes = 1
    TinctureStart = 2
    TinctureTypes = 2
    NumberOfMonths = 2
    [/b]
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.ChartType = xlLine
    
  For i = 1 To TinctureTypes
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.SeriesCollection(i).Name = "='Product Sales'!R" & TinctureStart + i - 1 & "C7"
    ActiveChart.SeriesCollection(i).Values = "='Product Sales'!R" & TinctureStart + i - 1 & "C8:R" & TinctureStart + i - 1 & "C" & 7 + NumberOfMonths
    ActiveChart.SeriesCollection(1).XValues = "='Product Sales'!R" & TinctureStart + TinctureTypes & "C8:R" & TinctureStart + TinctureTypes & "C" & 7 + NumberOfMonths
  Next i
    ActiveChart.SetElement (msoElementChartTitleCenteredOverlay)
    ActiveChart.ChartTitle.Select
    Selection.Caption = "='Product Sales'!R" & TinctureStart & "C5"
End Sub
i get TWO series plotted and my legend displays TWO series.

So I connot duplicate your problem, given the information you have provided.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top