ich versuche als Leihe folgendes zu lösen:
Über eine Userform habe ich mehrere (Anzahl 116) Checkboxen und 6 Textboxen gestaltet.
Auf Knopfdruck soll dann die Caption der angeklickten Checkbox und die Inhalte der Textboxen in eine vorgesehene Zelle in einem Tabellenblatt übernommen werden.
Der folgende Code funktioniert ja auch soweit für wenige Checkboxen. Wenn ich es verlängere für alle 116, dann erscheint die Fehlermeldung "Prozedur zu groß".
Hat jemand eine Idee wie es es besser bauen kann. Hier der Code:
Private Sub CommandButton2_Click()
Dim erste_freie_Zeile As Integer
erste_freie_Zeile = Sheets("Pos").Range("A65536").End(xlUp).Offset(1, 0).Row
If CheckBox1.Value = True Then
Sheets("Pos").Cells(erste_freie_Zeile, 2) = CheckBox1.Caption
Sheets("Pos").Cells(erste_freie_Zeile, 1) = Format(Vertrag.Text)
Sheets("Pos").Cells(erste_freie_Zeile, 3) = Format(Pos1.Text)
Sheets("Pos").Cells(erste_freie_Zeile, 4) = Format(Pos2.Text)
Sheets("Pos").Cells(erste_freie_Zeile, 5) = Format(Pos3.Text)
Sheets("Pos").Cells(erste_freie_Zeile, 6) = Format(Pos4.Text)
Sheets("Pos").Cells(erste_freie_Zeile, 7) = CDate(Datum.Text)
Unload Me
End If
If CheckBox2.Value = True Then
Sheets("Pos").Cells(erste_freie_Zeile, 2) = CheckBox2.Caption
Sheets("Pos").Cells(erste_freie_Zeile, 1) = Format(Vertrag.Text)
Sheets("Pos").Cells(erste_freie_Zeile, 3) = Format(Pos1.Text)
Sheets("Pos").Cells(erste_freie_Zeile, 4) = Format(Pos2.Text)
Sheets("Pos").Cells(erste_freie_Zeile, 5) = Format(Pos3.Text)
Sheets("Pos").Cells(erste_freie_Zeile, 6) = Format(Pos4.Text)
Sheets("Pos").Cells(erste_freie_Zeile, 7) = CDate(Datum.Text)
Unload Me
End If
If CheckBox3.Value = True Then
Sheets("Pos").Cells(erste_freie_Zeile, 2) = CheckBox3.Caption
Sheets("Pos").Cells(erste_freie_Zeile, 1) = Format(Vertrag.Text)
Sheets("Pos").Cells(erste_freie_Zeile, 3) = Format(Pos1.Text)
Sheets("Pos").Cells(erste_freie_Zeile, 4) = Format(Pos2.Text)
Sheets("Pos").Cells(erste_freie_Zeile, 5) = Format(Pos3.Text)
Sheets("Pos").Cells(erste_freie_Zeile, 6) = Format(Pos4.Text)
Sheets("Pos").Cells(erste_freie_Zeile, 7) = CDate(Datum.Text)
Unload Me
End If
If CheckBox4.Value = True Then
Sheets("Pos").Cells(erste_freie_Zeile, 2) = CheckBox4.Caption
Sheets("Pos").Cells(erste_freie_Zeile, 1) = Format(Vertrag.Text)
Sheets("Pos").Cells(erste_freie_Zeile, 3) = Format(Pos1.Text)
Sheets("Pos").Cells(erste_freie_Zeile, 4) = Format(Pos2.Text)
Sheets("Pos").Cells(erste_freie_Zeile, 5) = Format(Pos3.Text)
Sheets("Pos").Cells(erste_freie_Zeile, 6) = Format(Pos4.Text)
Sheets("Pos").Cells(erste_freie_Zeile, 7) = CDate(Datum.Text)
Unload Me
End If
End Sub
vielen Dank für Eure Antworten