Option
Explicit
Private
Sub
ToggleButton1_Click()
With
ToggleButton1
If
.Value
And
ChartObjects.Count = 0
And
.Caption <>
"Chart2"
Then
Call
Insert_Chart(pvstrAddress:=
"'"
& Name &
"'!$A$1:$C$7"
) '// Deine Bereiche anpassen...!!!!(s.u.)
.Caption =
"Delete_Chart1"
.ForeColor = vbRed
ElseIf
.Value
And
ChartObjects.Count = 0
And
.Caption =
"Chart2"
Then
Call
Insert_Chart(pvstrAddress:=
"'"
& Name &
"'!$A$11:$C$15"
)
.Caption =
"Delete_Chart2"
.ForeColor = vbRed
ElseIf
.Caption =
"Delete_Chart1"
Then
Call
ChartObjects.Delete
.Caption =
"Chart2"
.ForeColor = vbBlack
Else
Call
ChartObjects.Delete
.Caption =
"Chart1"
.ForeColor = vbBlack
End
If
End
With
End
Sub
Private
Sub
Insert_Chart(
ByVal
pvstrAddress
As
String
)
With
Shapes.AddChart.Chart
Call
.SetSourceData(Source:=Range(pvstrAddress))
.ChartType = xl3DColumnClustered
End
With
End
Sub