How to delete the empty series on a legend?

dboone25

Board Regular
Joined
May 8, 2015
Messages
185
hi, I am having a few difficulties using the xlXYScaller graph in where it adds in three blank series into the graph. Unsure how this works but this series indicates in the legend and looks a bit of a mess.

I have been trying to use this code:

HTML:
Dim c As Chart: Set c = activechart
Dim i As Integer
Dim a As Variant
c.HasLegend = False
c.HasLegend = True
n = 0 'Counter
For i = 1 To 6
a = c.SeriesCollection(i).Values
If WorksheetFunction.Sum(a) = 0 Then
c.Legend.LegendEntries(i-n).Delete 'Added in Counter
n = n+1 'Counter
End If
Next i

It gives me an error under '
HTML:
If Worksheetfunction.Sum(a) = 0
'Run-time error '13': Type mismatch


Not sure how to get around this or perhaps there is an easier way, thank you.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
I have taken your code directly into excel and have it exactly the same but it now throws an error:

Complie error:

Invalid or unqualified reference

This is at
Code:
For j = .SeriesCollection(z).Points.count To 1 Step -1

Should this include
Code:
c.SeriesCollection(z)


I have tried putting in the 'c' before .SeriesCollection and it throws a weird error:

Run-time error '5':

Invalid procedure call or argument.

Very strange.

I have not changed anything.Kept it exactly as you sent it.
 
Upvote 0
Yea, like I said...I wasn't able to test the code that I provided, which was taken from another site...so it's very possible it doesn't even work. I don't have any data to throw into a spreadsheet to test it with. It does need to have the "c." in there.

As for your other question regarding calling a second macro - exactly as I have it written:

Call MacroName

Like I've mentioned before, I don't work at all with charts so this is all foreign to me. So, if you can provide me with some data, any data, that I can throw into a spreadsheet in the same locations that your data exists, then I'd be able to run your code and get the same results that you're getting...from there, I can help out a lot more than I have been and it will eliminate a lot of the guessing games.
 
Upvote 0
Have a look at the data set im working with:


Data starts across in "B40" and ends in "V40" The data set ends in row 100. There is a gap inbetween 'stop' and 'no' only only column width..I hope that helps...let me know if you need anything else please ask..

notypedate_timerefinfoChanndeffrequencyampstopnotypedate_timerefinfoChanndeffrequencyampstop
403NX08/12/2011 11:51GNDYY3Output InformationMachine number 215000 - 40000 Hz57.1912994434903.47076404NX08/12/2011 11:51GNDYY4Output InformationMachine number 215000 - 40000 Hz57.1912994434903.47076
403NX19/04/2012 10:30GNDYY3Output InformationMachine number 315001 - 40000 Hz42.6916084334903.47076404NX19/04/2012 10:30GNDYY5Output InformationMachine number 315001 - 40000 Hz42.6916084334903.47076
403NX26/04/2012 12:36GNDYY3Output InformationMachine number 415002 - 40000 Hz45.2501983634903.47076404NX26/04/2012 12:36GNDYY6Output InformationMachine number 415002 - 40000 Hz45.2501983634903.47076
403NX04/05/2012 10:48GNDYY3Output InformationMachine number 515003 - 40000 Hz51.9332351734903.47076404NX04/05/2012 10:48GNDYY7Output InformationMachine number 515003 - 40000 Hz51.9332351734903.47076
403NX23/05/2012 20:28GNDYY3Output InformationMachine number 615004 - 40000 Hz60.7097625734903.47076404NX23/05/2012 20:28GNDYY8Output InformationMachine number 615004 - 40000 Hz60.7097625734903.47076
403NX25/05/2012 09:55GNDYY3Output InformationMachine number 715005 - 40000 Hz48.7888755834903.47076404NX25/05/2012 09:55GNDYY9Output InformationMachine number 715005 - 40000 Hz48.7888755834903.47076
403NX28/05/2012 12:13GNDYY3Output InformationMachine number 815006 - 40000 Hz80.3515243534903.47076404NX28/05/2012 12:13GNDYY10Output InformationMachine number 815006 - 40000 Hz80.3515243534903.47076
403NX19/06/2012 13:42GNDYY3Output InformationMachine number 915007 - 40000 Hz753.928466834903.47076404NX19/06/2012 13:42GNDYY11Output InformationMachine number 915007 - 40000 Hz753.928466834903.47076
403NX19/06/2012 16:27GNDYY3Output InformationMachine number 1015008 - 40000 Hz44.6401481634903.47076404NX19/06/2012 16:27GNDYY12Output InformationMachine number 1015008 - 40000 Hz44.6401481634903.47076
403NX20/06/2012 09:26GNDYY3Output InformationMachine number 1115009 - 40000 Hz40.1424140934903.47076404NX20/06/2012 09:26GNDYY13Output InformationMachine number 1115009 - 40000 Hz40.1424140934903.47076
403NX22/06/2012 13:02GNDYY3Output InformationMachine number 1215010 - 40000 Hz58.8170280534903.47076404NX22/06/2012 13:02GNDYY14Output InformationMachine number 1215010 - 40000 Hz58.8170280534903.47076
403NX22/06/2012 16:11GNDYY3Output InformationMachine number 1315011 - 40000 Hz37.5662956234903.47076404NX22/06/2012 16:11GNDYY15Output InformationMachine number 1315011 - 40000 Hz37.5662956234903.47076
403NX25/06/2012 10:36GNDYY3Output InformationMachine number 1415012 - 40000 Hz147.198623734903.47076404NX25/06/2012 10:36GNDYY16Output InformationMachine number 1415012 - 40000 Hz147.198623734903.47076
403NX02/07/2012 17:00GNDYY3Output InformationMachine number 1515013 - 40000 Hz61.0235214234903.47076404NX02/07/2012 17:00GNDYY17Output InformationMachine number 1515013 - 40000 Hz61.0235214234903.47076
403NX03/07/2012 14:06GNDYY3Output InformationMachine number 1615014 - 40000 Hz45.7090339734903.47076404NX03/07/2012 14:06GNDYY18Output InformationMachine number 1615014 - 40000 Hz45.7090339734903.47076
403NX06/07/2012 11:13GNDYY3Output InformationMachine number 1715015 - 40000 Hz40.1655502334903.47076404NX06/07/2012 11:13GNDYY19Output InformationMachine number 1715015 - 40000 Hz40.1655502334903.47076
403NX06/07/2012 13:41GNDYY3Output InformationMachine number 1815016 - 40000 Hz91.5370559734903.47076404NX06/07/2012 13:41GNDYY20Output InformationMachine number 1815016 - 40000 Hz91.5370559734903.47076
403NX09/07/2012 10:05GNDYY3Output InformationMachine number 1915017 - 40000 Hz84.8855819734903.47076404NX09/07/2012 10:05GNDYY21Output InformationMachine number 1915017 - 40000 Hz84.8855819734903.47076
403NX09/07/2012 13:05GNDYY3Output InformationMachine number 2015018 - 40000 Hz50.5321960434903.47076404NX09/07/2012 13:05GNDYY22Output InformationMachine number 2015018 - 40000 Hz50.5321960434903.47076
403NX10/07/2012 09:27GNDYY3Output InformationMachine number 2115019 - 40000 Hz63.0579414434903.47076404NX10/07/2012 09:27GNDYY23Output InformationMachine number 2115019 - 40000 Hz63.0579414434903.47076
403NX10/07/2012 12:41GNDYY3Output InformationMachine number 2215020 - 40000 Hz40.8844413834903.47076404NX10/07/2012 12:41GNDYY24Output InformationMachine number 2215020 - 40000 Hz40.8844413834903.47076
403NX12/07/2012 10:18GNDYY3Output InformationMachine number 2315021 - 40000 Hz43.5076484734903.47076404NX12/07/2012 10:18GNDYY25Output InformationMachine number 2315021 - 40000 Hz43.5076484734903.47076
403NX19/07/2012 09:15GNDYY3Output InformationMachine number 2415022 - 40000 Hz475.917633134903.47076404NX19/07/2012 09:15GNDYY26Output InformationMachine number 2415022 - 40000 Hz475.917633134903.47076
403NX24/07/2012 15:19GNDYY3Output InformationMachine number 2515023 - 40000 Hz45.095905334903.47076404NX24/07/2012 15:19GNDYY27Output InformationMachine number 2515023 - 40000 Hz45.095905334903.47076
403NX10/08/2012 15:57GNDYY3Output InformationMachine number 2615024 - 40000 Hz39.4282531734903.47076404NX10/08/2012 15:57GNDYY28Output InformationMachine number 2615024 - 40000 Hz39.4282531734903.47076
403NX14/08/2012 16:53GNDYY3Output InformationMachine number 2715025 - 40000 Hz49.835548434903.47076404NX14/08/2012 16:53GNDYY29Output InformationMachine number 2715025 - 40000 Hz49.835548434903.47076
403NX15/08/2012 14:52GNDYY3Output InformationMachine number 2815026 - 40000 Hz43.7846717834903.47076404NX15/08/2012 14:52GNDYY30Output InformationMachine number 2815026 - 40000 Hz43.7846717834903.47076
403NX15/08/2012 20:39GNDYY3Output InformationMachine number 2915027 - 40000 Hz45.7649879534903.47076404NX15/08/2012 20:39GNDYY31Output InformationMachine number 2915027 - 40000 Hz45.7649879534903.47076
403NX16/08/2012 09:48GNDYY3Output InformationMachine number 3015028 - 40000 Hz35.3103065534903.47076404NX16/08/2012 09:48GNDYY32Output InformationMachine number 3015028 - 40000 Hz35.3103065534903.47076
403NX16/08/2012 14:56GNDYY3Output InformationMachine number 3115029 - 40000 Hz80.0158538834903.47076404NX16/08/2012 14:56GNDYY33Output InformationMachine number 3115029 - 40000 Hz80.0158538834903.47076
403NX22/08/2012 09:49GNDYY3Output InformationMachine number 3215030 - 40000 Hz334.120910634903.47076404NX22/08/2012 09:49GNDYY34Output InformationMachine number 3215030 - 40000 Hz334.120910634903.47076
403NX22/08/2012 20:32GNDYY3Output InformationMachine number 3315031 - 40000 Hz53.8985290534903.47076404NX22/08/2012 20:32GNDYY35Output InformationMachine number 3315031 - 40000 Hz53.8985290534903.47076
403NX03/09/2012 15:06GNDYY3Output InformationMachine number 3415032 - 40000 Hz49.3163604734903.47076404NX03/09/2012 15:06GNDYY36Output InformationMachine number 3415032 - 40000 Hz49.3163604734903.47076
403NX05/09/2012 15:08GNDYY3Output InformationMachine number 3515033 - 40000 Hz51.1859664934903.47076404NX05/09/2012 15:08GNDYY37Output InformationMachine number 3515033 - 40000 Hz51.1859664934903.47076
403NX06/09/2012 09:52GNDYY3Output InformationMachine number 3615034 - 40000 Hz45.0495300334903.47076404NX06/09/2012 09:52GNDYY38Output InformationMachine number 3615034 - 40000 Hz45.0495300334903.47076
403NX06/09/2012 20:16GNDYY3Output InformationMachine number 3715035 - 40000 Hz63.8142509534903.47076404NX06/09/2012 20:16GNDYY39Output InformationMachine number 3715035 - 40000 Hz63.8142509534903.47076
403NX07/09/2012 08:53GNDYY3Output InformationMachine number 3815036 - 40000 Hz60.9896812434903.47076404NX07/09/2012 08:53GNDYY40Output InformationMachine number 3815036 - 40000 Hz60.9896812434903.47076
403NX11/09/2012 10:00GNDYY3Output InformationMachine number 3915037 - 40000 Hz91.9719314634903.47076404NX11/09/2012 10:00GNDYY41Output InformationMachine number 3915037 - 40000 Hz91.9719314634903.47076
403NX11/09/2012 10:14GNDYY3Output InformationMachine number 4015038 - 40000 Hz44.7521781934903.47076404NX11/09/2012 10:14GNDYY42Output InformationMachine number 4015038 - 40000 Hz44.7521781934903.47076
403NX11/09/2012 13:17GNDYY3Output InformationMachine number 4115039 - 40000 Hz53.3783912734903.47076404NX11/09/2012 13:17GNDYY43Output InformationMachine number 4115039 - 40000 Hz53.3783912734903.47076
403NX11/09/2012 18:56GNDYY3Output InformationMachine number 4215040 - 40000 Hz57.9430732734903.47076404NX11/09/2012 18:56GNDYY44Output InformationMachine number 4215040 - 40000 Hz57.9430732734903.47076
403NX17/09/2012 19:45GNDYY3Output InformationMachine number 4315041 - 40000 Hz2535.9575234903.47076404NX17/09/2012 19:45GNDYY45Output InformationMachine number 4315041 - 40000 Hz2535.9575234903.47076
403NX18/09/2012 19:49GNDYY3Output InformationMachine number 4415042 - 40000 Hz59.8880195634903.47076404NX18/09/2012 19:49GNDYY46Output InformationMachine number 4415042 - 40000 Hz59.8880195634903.47076
403NX19/09/2012 17:01GNDYY3Output InformationMachine number 4515043 - 40000 Hz49.8959388734903.47076404NX19/09/2012 17:01GNDYY47Output InformationMachine number 4515043 - 40000 Hz49.8959388734903.47076
403NX01/10/2012 14:54GNDYY3Output InformationMachine number 4615044 - 40000 Hz43.7371292134903.47076404NX01/10/2012 14:54GNDYY48Output InformationMachine number 4615044 - 40000 Hz43.7371292134903.47076
403NX01/10/2012 16:25GNDYY3Output InformationMachine number 4715045 - 40000 Hz41.9957733234903.47076404NX01/10/2012 16:25GNDYY49Output InformationMachine number 4715045 - 40000 Hz41.9957733234903.47076
403NX02/10/2012 09:17GNDYY3Output InformationMachine number 4815046 - 40000 Hz95.8531036434903.47076404NX02/10/2012 09:17GNDYY50Output InformationMachine number 4815046 - 40000 Hz95.8531036434903.47076
403NX03/10/2012 10:01GNDYY3Output InformationMachine number 4915047 - 40000 Hz50.9145088234903.47076404NX03/10/2012 10:01GNDYY51Output InformationMachine number 4915047 - 40000 Hz50.9145088234903.47076
403NX19/10/2012 12:25GNDYY3Output InformationMachine number 5015048 - 40000 Hz32.9361267134903.47076404NX19/10/2012 12:25GNDYY52Output InformationMachine number 5015048 - 40000 Hz32.9361267134903.47076
403NX19/10/2012 13:54GNDYY3Output InformationMachine number 5115049 - 40000 Hz50.0330963134903.47076404NX19/10/2012 13:54GNDYY53Output InformationMachine number 5115049 - 40000 Hz50.0330963134903.47076
403NX25/10/2012 09:17GNDYY3Output InformationMachine number 5215050 - 40000 Hz41.8848342934903.47076404NX25/10/2012 09:17GNDYY54Output InformationMachine number 5215050 - 40000 Hz41.8848342934903.47076
403NX25/10/2012 11:04GNDYY3Output InformationMachine number 5315051 - 40000 Hz72.5357818634903.47076404NX25/10/2012 11:04GNDYY55Output InformationMachine number 5315051 - 40000 Hz72.5357818634903.47076
403NX25/10/2012 13:11GNDYY3Output InformationMachine number 5415052 - 40000 Hz57.7315521234903.47076404NX25/10/2012 13:11GNDYY56Output InformationMachine number 5415052 - 40000 Hz57.7315521234903.47076
403NX25/10/2012 14:40GNDYY3Output InformationMachine number 5515053 - 40000 Hz48.9230384834903.47076404NX25/10/2012 14:40GNDYY57Output InformationMachine number 5515053 - 40000 Hz48.9230384834903.47076
403NX29/10/2012 14:17GNDYY3Output InformationMachine number 5615054 - 40000 Hz74.3162231434903.47076404NX29/10/2012 14:17GNDYY58Output InformationMachine number 5615054 - 40000 Hz74.3162231434903.47076
403NX29/10/2012 14:25GNDYY3Output InformationMachine number 5715055 - 40000 Hz1130.54162634903.47076404NX29/10/2012 14:25GNDYY59Output InformationMachine number 5715055 - 40000 Hz1130.54162634903.47076
403NX29/10/2012 19:12GNDYY3Output InformationMachine number 5815056 - 40000 Hz1987.03381334903.47076404NX29/10/2012 19:12GNDYY60Output InformationMachine number 5815056 - 40000 Hz1987.03381334903.47076
403NX30/10/2012 14:29GNDYY3Output InformationMachine number 5915057 - 40000 Hz56.840557134903.47076404NX30/10/2012 14:29GNDYY61Output InformationMachine number 5915057 - 40000 Hz56.840557134903.47076
403NX05/11/2012 13:15GNDYY3Output InformationMachine number 6015058 - 40000 Hz41.7861976634903.47076404NX05/11/2012 13:15GNDYY62Output InformationMachine number 6015058 - 40000 Hz41.7861976634903.47076
403NX05/11/2012 19:04GNDYY3Output InformationMachine number 6115059 - 40000 Hz5145.7812534903.47076404NX05/11/2012 19:04GNDYY63Output InformationMachine number 6115059 - 40000 Hz5145.7812534903.47076

<tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0
Just wanted to let you know that I've seen your post. I'm off of work today, but I'll have a look and do some messing around in excel tomorrow at work.
 
Upvote 0
Here's what I used:

Code:
Private Sub CommandButton3_Click()
Dim rXVals As Range
Dim rYVals As Range
Dim i As Long

Dim LastRow As Long
Dim Name As Range


With Worksheets("Sheet1")
    LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
    
    If LastRow < 41 Then
        MsgBox "No data found.", vbInformation
        Exit Sub
    End If

    Set rXVals = .Range("C41:C" & LastRow)
    
    Set rYVals = .Range("I41:J" & LastRow)
End With

With ActiveSheet.ChartObjects.Add(Left:=30, Width:=650, Top:=20, Height:=375).Chart
    .ChartType = xlXYScatter

    For i = 1 To rYVals.Columns.Count
        With .SeriesCollection.NewSeries
            .Name = "=Sheet1!$E$41" ' CI
    
            .XValues = rXVals
            .Values = rYVals.Columns(i)
    
            'Edit marker type
            Select Case i
                Case 1
                    .MarkerSize = 5
                    .MarkerStyle = xlMarkerStyleStar
                Case 2
                    .MarkerSize = 5
                    .MarkerStyle = xlMarkerStyleCircle
            End Select
        End With
    Next i
End With
End Sub

I didn't receive any empty series with the data you provided - I only have 2 and they both appear to be not empty. Although I'm sure there's a prettier way to do it, this also allows for different MarkerStyle's for each of the series.

I also changed everything to Sheet1, so you'll need to change it back to Sheet2.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top