Option Explicit
Public PlotName As String
Public PlotRange As Range
Sub Tester()
Range("TCKWH.V.1").Select
AddPlot ActiveSheet.Range("C9:C13,D9:O13")
End Sub
Sub AddPlot(rng As Range)
With ActiveSheet.Shapes.AddChart
PlotName = .Name
.Chart.ChartType = xlLineMarkers
.Chart.SetSourceData Source:=Range(rng.Address())
.Chart.HasTitle = True
.Chart.ChartTitle.Text = Range("C9")
End With
Set PlotRange = rng
Application.EnableEvents = False
rng.Select
Application.EnableEvents = True
End Sub
Sub RemovePlot(rng As Range)
If Not PlotRange Is Nothing Then
If Application.Intersect(rng, PlotRange) Is Nothing Then
On Error Resume Next
rng.Parent.Shapes(PlotName).Delete
On Error GoTo 0
End If
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
RemovePlot Target
End Sub
我有这个代码,根据通过复选框接受的信息创建图表。但是,您未选择的任何帐户都显示为“空白”图例条目 是否有宏代码删除“空白”图例条目?
答案 0 :(得分:0)
在表格下方创建另一个表格。然后将复选框链接到第一个表下面的表格。然后在True / False之后输入=IF($B10=TRUE,C3,"")
之后,将AddPlot ActiveSheet.Range("C9:C13,D9:O13")
替换为底部表的范围。