|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
示例中在创建chartobjects时,使用了“Set apiechart = .ChartObjects.Add(.Cells(13, 1).Left, .Cells(13, 1).Top, w, h)”语句,想通过添加"apiechart.Delete"语句,在每次点击示例按钮时将之前创建的chartobjects对象删除,但是无法删除掉,还请各位师兄指点;
示例全文:
Private Sub CommandButton1_Click()
With Sheet1
On Error Resume Next
apiechart.Delete
maxc = .Range("az20").End(xlToLeft).Column
s = Split(.Cells(1, maxc).Address, "$")(1)
Set DataRange = .Range("c21:" & s & "21")
Set Rng = .Range("a13:" & s & "17")
w = Rng.Width
h = Rng.Height
Set apiechart = .ChartObjects.Add(.Cells(13, 1).Left, .Cells(13, 1).Top, w, h)
With apiechart.Chart
.PlotVisibleOnly = False
.ShowCategoryName = True
.ShowPercentage = True
.ChartType = xlPie
.SetSourceData Source:=DataRange, PlotBy:=xlRows
.ApplyDataLabels ShowValue:=True
.HasTitle = False
With .ChartArea.Interior
.ColorIndex = 8
.PatternColorIndex = 1
.Pattern = xlSolid
End With
With .PlotArea.Interior
.ColorIndex = 35
.PatternColorIndex = 1
.Pattern = xlSolid
End With
With .SeriesCollection(1)
.Select
.AxisGroup = 2
.Name = "=Sheet1!$A$21"
.XValues = Range("b20:" & s & "20")
End With
End With
End With
End Sub
|
|