Clever-Excel-Forum

Normale Version: langsame Datei
Du siehst gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Seiten: 1 2 3
Besser so:


Code:
Private Sub CommandButton1_Click()
  Tabelle1.Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(, 39) = Array(TextBox1, TextBox2, TextBox3, "", "", "", "", TextBox4, ComboBox1, TextBox6, "", "", "", TextBox7, ComboBox2, TextBox9, "", "", "", TextBox10, ComboBox3, TextBox12, "","","",TextBox13, ComboBox4, TextBox15)
   
   For Each it In Controls
      If TypeName(it) = "Textbox" Then it.Text = ""
      If TypeName(it) = "ComboBox" Then it.ListIndex = -1
    Next
End Sub
Hi Snb,

da ich leider nicht der VBA künstler bin steige ich durch meinen Code besser durch. Ich musste jetzt ja den Aufbau auf Grund der Inderekt Fkt. ändern. Trotzdem Danke für deine Überlegungen

Somit sieht der neue Code wie folgt aus


Code:
'Button:  Übernehmen
Private Sub CommandButton1_Click()
Dim lz1 As Long   'LastZell in Tabelle1
 On Error GoTo Fehler
 lz1 = Cells(Rows.Count, 1).End(xlUp).Row + 1
 'Mixkiste
 Cells(lz1, 1) = TextBox1.Text
 Cells(lz1, 2) = TextBox2.Text
 Cells(lz1, 3) = TextBox3.Text
 'Sorte 1
 Cells(lz1, 8) = TextBox4.Text
 Cells(lz1, 9) = ComboBox1.Text
 Cells(lz1, 10) = TextBox6.Text
 'Sorte 2
 Cells(lz1, 16) = TextBox7.Text
 Cells(lz1, 17) = ComboBox2.Text
 Cells(lz1, 18) = TextBox9.Text
 'Sorte 3
 Cells(lz1, 24) = TextBox10.Text
 Cells(lz1, 25) = ComboBox3.Text
 Cells(lz1, 26) = TextBox12.Text
 'Sorte 4
 Cells(lz1, 32) = TextBox13.Text
 Cells(lz1, 33) = ComboBox4.Text
 Cells(lz1, 34) = TextBox15.Text
'Leeren
  TextBox1.Text = Empty
  TextBox2.Text = Empty
  TextBox3.Text = Empty
  TextBox4.Text = Empty
 ComboBox1.Text = -1
  TextBox6.Text = Empty
  TextBox7.Text = Empty
  ComboBox2.Text = -1
  TextBox9.Text = Empty
  TextBox10.Text = Empty
  ComboBox3.Text = -1
  TextBox12.Text = Empty
  TextBox13.Text = Empty
 ComboBox4.Text = -1
  TextBox15.Text = Empty
 

Exit Sub

Fehler:  MsgBox "Eingabe Fehler aufgetreten"
End Sub

'Button:  Abbrechen
Private Sub CommandButton2_Click()
 Unload Me
End Sub

Private Sub UserForm_Click()

End Sub
Das finde ich übersichtlicher auch wenn es länger zum schreiben braucht. Viel verstehe ich in deinem Code noch nicht. Gibt es bei deinem Code noch andere Vorteile ausser das er kürzer ist.
Ich nutze diesen Code auch für andere UF. Wo ich dann recht übersichtlich (wie gesagt für mich ist der leichter zu verstehen) Änderungen vornehmen kann.


MFG

Sven
Seiten: 1 2 3