Code kürzen durch Schleife
26.03.2019 01:31:07
benny124aka
Ich würde gerne den bzw. die folgenden Code´s als Schleife schreiben, schaffe es aber leider nicht die Textboxen innerhalb der Schleife anzusprechen.
In den Textboxen befinden sich Zahlen, Buchstaben und ein Datum
So siehts bisher aus:(funktioniert auch, ist aber sehr lang!Außerdem ist es so sehr umständlich bei Erweiterung.- Geht das auch als Schleife?)
1.Code
Private Sub cmd_save_Click()
Dim intErsteLeereZeile As Long
'bestimmt die erste freie Zeile im Tabelleblatt
intErsteLeereZeile = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row + 1
ActiveSheet.Cells(intErsteLeereZeile, 1).Value = Me.TextBox1
ActiveSheet.Cells(intErsteLeereZeile, 2).Value = Me.TextBox2
ActiveSheet.Cells(intErsteLeereZeile, 3).Value = Me.TextBox3
ActiveSheet.Cells(intErsteLeereZeile, 4).Value = Me.TextBox4
ActiveSheet.Cells(intErsteLeereZeile, 5).Value = Me.TextBox5
ActiveSheet.Cells(intErsteLeereZeile, 6).Value = Me.TextBox6
'Rechnungsdatum
With ActiveSheet.Cells(intErsteLeereZeile, 7)
If Me.TextBox7.Text = "" Then
.ClearContents
ElseIf IsDate(Me.TextBox7.Text) Then
.Value = CDate(Me.TextBox7)
Else
.Value = Me.TextBox7
End If
End With
ActiveSheet.Cells(intErsteLeereZeile, 8).Value = Me.TextBox8
ActiveSheet.Cells(intErsteLeereZeile, 9).Value = Me.TextBox9
ActiveSheet.Cells(intErsteLeereZeile, 10).Value = Me.TextBox10
ActiveSheet.Cells(intErsteLeereZeile, 11).Value = Me.TextBox11
ActiveSheet.Cells(intErsteLeereZeile, 12).Value = Me.TextBox12
ActiveSheet.Cells(intErsteLeereZeile, 13).Value = Me.TextBox13
ActiveSheet.Cells(intErsteLeereZeile, 14).Value = Me.TextBox14
ActiveSheet.Cells(intErsteLeereZeile, 15).Value = Me.TextBox15
ActiveSheet.Cells(intErsteLeereZeile, 16).Value = Me.TextBox16
Unload frm_Erfassen
End Sub
.................................................................................
2.Code
z ist eine Global As Integer Variable
.................................................................................
Private Sub cmd_save_Click()
Sheets("Tabelle1").Cells(Z, 1) = TextBox1
Sheets("Tabelle1").Cells(Z, 2) = TextBox2
Sheets("Tabelle1").Cells(Z, 3) = TextBox3
Sheets("Tabelle1").Cells(Z, 4) = TextBox4
Sheets("Tabelle1").Cells(Z, 5) = TextBox5
Sheets("Tabelle1").Cells(Z, 6) = TextBox6
Sheets("Tabelle1").Cells(Z, 7) = TextBox7
Sheets("Tabelle1").Cells(Z, 8) = TextBox8
Sheets("Tabelle1").Cells(Z, 9) = TextBox9
Sheets("Tabelle1").Cells(Z, 10) = TextBox10
Sheets("Tabelle1").Cells(Z, 11) = TextBox11
Sheets("Tabelle1").Cells(Z, 12) = TextBox12
Sheets("Tabelle1").Cells(Z, 13) = TextBox13
Sheets("Tabelle1").Cells(Z, 14) = TextBox14
Sheets("Tabelle1").Cells(Z, 15) = TextBox15
Sheets("Tabelle1").Cells(Z, 16) = TextBox16
Unload frm_Bearbeiten
End Sub
...........................................................................
Wäre für eure Hilfe sehr dankbar :)
gruß benny