1
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

我有这段代码可以根据通过复选框接受的信息创建图表。但是您未选择的任何帐户都显示为“空白”图例条目是否有删除“空白”图例条目的宏代码?

在此处输入图像描述

4

1 回答 1

0

在表格下方创建另一个表格。然后将复选框链接到第一个表格下方的表格。然后在 True/False 之后输入=IF($B10=TRUE,C3,"")

之后将 AddPlot 替换ActiveSheet.Range("C9:C13,D9:O13")为底部表格的范围。

在此处输入图像描述

于 2013-06-27T04:54:15.403 回答