Clever-Excel-Forum

Normale Version: VBA Grafik ein- ausblenden lassen
Du siehst gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Hallo!
Ich habe eine Frage zu meinem VBA Code:
Hier werden je nach Click auf Option Buttons bestimmte Grafiken ein- oder ausgeblendet. Funktioniert soweit auch gut.

Code:
Private Sub OptionButton1_Click()
 ShapesEinAus
End Sub
Private Sub OptionButton2_Click()
 ShapesEinAus
End Sub
Private Sub OptionButton3_Click()
 ShapesEinAus
End Sub
Private Sub OptionButton4_Click()
 ShapesEinAus
End Sub
Private Sub OptionButton5_Click()
 ShapesEinAus
End Sub
Private Sub OptionButton6_Click()
 ShapesEinAus
End Sub
Private Sub OptionButton7_Click()
 ShapesEinAus
End Sub

Sub ShapesEinAus()
 With Tabelle17
   .Shapes(1).Visible = .OptionButton1.Value
   .Shapes(2).Visible = .OptionButton2.Value
   .Shapes("Gruppieren 64529").Visible = .OptionButton3.Value 'Zahl wurde beim Gruppieren automatisch vergeben, deswegen 64529
   .Shapes("Gruppieren 50").Visible = .OptionButton4.Value
   .Shapes("Gruppieren 54").Visible = .OptionButton5.Value
   .Shapes("Gruppieren 58").Visible = .OptionButton6.Value
   .Shapes("Gruppieren 62").Visible = .OptionButton7.Value
 End With
End Sub

Jetzt wollte ich eine weitere Grafik hinzufügen und hab meinen Code entsprechend angepasst:
Code:
Private Sub OptionButton1_Click()
 ShapesEinAus
End Sub
Private Sub OptionButton2_Click()
 ShapesEinAus
End Sub
Private Sub OptionButton3_Click()
 ShapesEinAus
End Sub
Private Sub OptionButton4_Click()
 ShapesEinAus
End Sub
Private Sub OptionButton5_Click()
 ShapesEinAus
End Sub
Private Sub OptionButton6_Click()
 ShapesEinAus
End Sub
Private Sub OptionButton7_Click()
 ShapesEinAus
End Sub
Private Sub OptionButton8_Click() 'wurde neu hinzugefügt
 ShapesEinAus
End Sub

Sub ShapesEinAus()
 With Tabelle17
   .Shapes(1).Visible = .OptionButton1.Value
   .Shapes(2).Visible = .OptionButton2.Value
   .Shapes("Gruppieren 64529").Visible = .OptionButton3.Value
   .Shapes("Gruppieren 50").Visible = .OptionButton4.Value
   .Shapes("Gruppieren 54").Visible = .OptionButton5.Value
   .Shapes("Gruppieren 58").Visible = .OptionButton6.Value
   .Shapes("Gruppieren 62").Visible = .OptionButton7.Value
   .Shapes(67).Visible = .OptionButton8.Value 'wurde neu hinzugefügt
 End With
End Sub

Leider scheint das nicht zu gehen, ich bekomme folgende Meldung:
Code:
Laufzeitfehler ’-2147024809 (80070057)’:
Der Index in der angegebenen Sammlung ist außerhalb des zulässigen Bereichs.


Woran könnte das liegen? Danke für die Hinweiße,

Gruß
Hallo,

vielleicht mit

.Shapes("Gruppieren 67") = ... ?

Gruß Uwe
Hab das ganze nicht gruppiert, aber namen vergeben und anschließend alle Options Buttons gelöscht und neu angelegt. Danach hat es gut funktioniert! Danke für den Denkanstoß!

Gruß!