vba 删除动态图表中的所有数据系列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12941356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Deleting all the data series in a dynamic chart
提问by Alvi John
I create a dynamic chart on multiple data series according to the selection I make in the listbox (Lbox1).
我根据我在列表框 (Lbox1) 中所做的选择,在多个数据系列上创建了一个动态图表。
It throws an error when I delete all the data series initially to make a fresh chart.
当我最初删除所有数据系列以制作新图表时,它会引发错误。
Public Sub listbox_selection()
Dim i As Integer
Dim temp As String
Dim k As Integer
Dim s As SeriesCollection
k = Sheets("Plan1").ChartObjects(1).Chart.SeriesCollection.count
##This part giving error
For i = 1 To k
Sheets("Plan1").ChartObjects(1).Chart.SeriesCollection(i).Delete
Next
####
Sheets("Plan1").ListBoxes("LBox1").Select
For i = 1 To Sheets("Plan1").Shapes("LBox1").ControlFormat.ListCount
If Sheets("Plan1").ListBoxes("LBox1").Selected(i) = True Then
Call Listit(X:=i)
End If
Next
End Sub
Public Sub Listit(ByVal X As Integer)
X = X + 3
With Sheets("Plan1").ChartObjects(1).Chart
With .SeriesCollection.NewSeries
.XValues = Range("Q2:U2")
.Values = Range("Q" & X & ":U" & X & "")
.Name = Range("P" & X).Value
End With
End With
End Sub
回答by nightcrawler23
Try this,
尝试这个,
Sub temp()
ActiveSheet.ChartObjects("Chart 1").Activate
For Each s In ActiveChart.SeriesCollection
s.Delete
Next s
End Sub
回答by 3alster
You can use Sheets("Plan1").ChartObjects(1).Chart.ChartArea.ClearContents
您可以使用 Sheets("Plan1").ChartObjects(1).Chart.ChartArea.ClearContents
回答by Lionel
Excel 2010
Excel 2010
ActiveChart.ChartArea.ClearContents