nreynolds
01-02-2015, 03:36 PM
I trying to develop a macro that will populate a number of data points onto an Excel XY Scatter plot that already has two data series plotted. The macro currently works fine as far as loading the data points as a series and a few edits to position corresponding data labels. However, I would also like the legend to only show information on the two original data series. The subsequent data points should only be labeled on the chart using data labels....not the chart legend. Below is the code I'm trying to use for deleting the legend entries.
Private Sub ClearLegend()
Dim z As Integer
Worksheets("HGL vs Pipeline").ChartObjects("Pipeline Profile").Activate
For z = ActiveChart.SeriesCollection.Count To 3 Step -1
ActiveChart.Legend.LegendEntries(z).Delete
Next
End Sub
It may also be important to note that on the same worksheet I have a macro-enabled button that clears the chart. The first time I populate the chart, the legend keys are deleted as anticipated. However, if I clear the chart and attempt the re-populate with the data points, I get the following error: "System Error &H80004005 (-2147467529). Unspecified error"
Perhaps, the issue lies somewhere in the chart clearing process? That coding is shown below.
Sub ClearChart()
Dim i As Integer
ActiveSheet.ChartObjects("Pipeline Profile").Activate
ActiveChart.PlotArea.Select
For i = ActiveChart.SeriesCollection.Count To 3 Step -1
ActiveChart.SeriesCollection(i).Delete
Next
End Sub
The idea is to allow the user to populate the chart with the certain data points. Then, if changes need to be made later, they can clear the chart and then display whatever new point information they wish...let me know if more information is needed.
Private Sub ClearLegend()
Dim z As Integer
Worksheets("HGL vs Pipeline").ChartObjects("Pipeline Profile").Activate
For z = ActiveChart.SeriesCollection.Count To 3 Step -1
ActiveChart.Legend.LegendEntries(z).Delete
Next
End Sub
It may also be important to note that on the same worksheet I have a macro-enabled button that clears the chart. The first time I populate the chart, the legend keys are deleted as anticipated. However, if I clear the chart and attempt the re-populate with the data points, I get the following error: "System Error &H80004005 (-2147467529). Unspecified error"
Perhaps, the issue lies somewhere in the chart clearing process? That coding is shown below.
Sub ClearChart()
Dim i As Integer
ActiveSheet.ChartObjects("Pipeline Profile").Activate
ActiveChart.PlotArea.Select
For i = ActiveChart.SeriesCollection.Count To 3 Step -1
ActiveChart.SeriesCollection(i).Delete
Next
End Sub
The idea is to allow the user to populate the chart with the certain data points. Then, if changes need to be made later, they can clear the chart and then display whatever new point information they wish...let me know if more information is needed.