Live-Forum - Die aktuellen Beiträge
Datum
Titel
16.10.2025 17:40:39
16.10.2025 17:25:38
Anzeige
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Maske - Reihenfolge ändern

Forumthread: Maske - Reihenfolge ändern

Maske - Reihenfolge ändern
12.10.2015 13:12:36
Mike
Hallo Forum,
ich erfasse Daten mit dem nachfolgenden VBA Formular. Aktuell werden die Daten immer untern angefügt.
Option Explicit

Private Sub ComboBox1_Click()
If ComboBox1.ListIndex  0 Then
TextBox1 = Cells(ComboBox1.ListIndex + 1, 1)
TextBox2 = Cells(ComboBox1.ListIndex + 1, 2)
TextBox3 = Cells(ComboBox1.ListIndex + 1, 3)
TextBox4 = Cells(ComboBox1.ListIndex + 1, 4)
TextBox5 = Cells(ComboBox1.ListIndex + 1, 5)
TextBox6 = Cells(ComboBox1.ListIndex + 1, 6)
TextBox7 = Cells(ComboBox1.ListIndex + 1, 7)
TextBox8 = Cells(ComboBox1.ListIndex + 1, 8)
TextBox9 = Cells(ComboBox1.ListIndex + 1, 9)
Else
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
TextBox5 = ""
TextBox6 = ""
TextBox7 = ""
TextBox8 = ""
TextBox9 = ""
End If
End Sub

Private Sub CommandButton1_Click()
If ComboBox1.ListIndex > 0 Then
Rows(ComboBox1.ListIndex + 1).Delete
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
TextBox5 = ""
TextBox6 = ""
TextBox7 = ""
TextBox8 = ""
TextBox9 = ""
UserForm_Initialize
End If
End Sub

Private Sub CommandButton2_Click()
Dim xZeile As Long
If TextBox1 = "" Then Exit Sub
If ComboBox1.ListIndex = 0 Then
xZeile = [A65536].End(xlUp).Row + 1
Else
xZeile = ComboBox1.ListIndex + 1
End If
Cells(xZeile, 1) = TextBox1
Cells(xZeile, 2) = TextBox2
Cells(xZeile, 3) = TextBox3
Cells(xZeile, 4) = TextBox4
Cells(xZeile, 5) = TextBox5
Cells(xZeile, 6) = TextBox6
Cells(xZeile, 7) = TextBox7
Cells(xZeile, 8) = TextBox8
Cells(xZeile, 9) = TextBox9
UserForm_Initialize
End Sub

Private Sub CommandButton3_Click()
Unload Me
End Sub

Private Sub Label1_Click()
End Sub

Private Sub Label6_Click()
End Sub

Private Sub Label9_Click()
End Sub

Private Sub TextBox3_Change()
End Sub

Private Sub UserForm_Initialize()
Dim aRow, i As Long
Application.EnableEvents = False
ComboBox1.Clear
aRow = [A65536].End(xlUp).Row
ComboBox1.AddItem "neue Person hinzufügen"
For i = 2 To aRow
ComboBox1.AddItem Cells(i, 1) & ", " & Cells(i, 2)
Next i
ComboBox1.ListIndex = 0
Application.EnableEvents = True
End Sub

Ich hätte sie aber gerne immer in die zweite Zeile eingefügt. Kann mir jemand helfen?
Gruß Mike

Anzeige

5
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Maske - Reihenfolge ändern
12.10.2015 21:09:01
fcs
Hallo Mike,
etwa mit nachfolgenden Anpassungen, die in Zeile 2 eine Leerzeile einfügen und anschliessen die Werte eintragen.
Du solltest aber die Funktionslosen Ereignismakros (Labels, Textbox3, etc.) rausschmeißen. Dies verwirren nur.
Gruß
Franz
Private Sub CommandButton2_Click()
Dim xZeile As Long, wks As Worksheet
If TextBox1 = "" Then Exit Sub
Application.ScreenUpdating = False
Set wks = ActiveSheet
With wks
If ComboBox1.ListIndex = 0 Then
xZeile = 2
.Rows(xZeile).Copy
.Rows(xZeile + 1).Insert
.Rows(xZeile).ClearContents
Else
xZeile = ComboBox1.ListIndex + 1
End If
.Cells(xZeile, 1) = TextBox1
.Cells(xZeile, 2) = TextBox2
.Cells(xZeile, 3) = TextBox3
.Cells(xZeile, 4) = TextBox4
.Cells(xZeile, 5) = TextBox5
.Cells(xZeile, 6) = TextBox6
.Cells(xZeile, 7) = TextBox7
.Cells(xZeile, 8) = TextBox8
.Cells(xZeile, 9) = TextBox9
End With
Application.ScreenUpdating = True
UserForm_Initialize
End Sub

Anzeige
AW: Maske - Reihenfolge ändern
13.10.2015 10:07:33
Mike
Hallo Franz,
danke, das funktioniert...
Jetzt habe ich allerdings ein neues Problem. Der Code fügt leider eine komplette Zeile ein. Es sollten jedoch nur die 9 Felder eingefügt bzw. nach unter verschoben werden, da im Tabellenblatt weiter hinten in der Zeile weitere Formeln hinterlegt sind.
Gruß Mik

Anzeige
AW: Maske - Reihenfolge ändern
14.10.2015 18:45:48
fcs
Hallo Mike,
passe den folgenden Abschnitt meines Makros an:
        If ComboBox1.ListIndex = 0 Then
xZeile = 2
.Range(.Cells(xZeile, 1).Cells(xZeile, 9)).Copy
.Range(.Cells(xZeile + 1, 1).Cells(xZeile +1, 9)).Insert Shift:=xlShiftDown
.Range(.Cells(xZeile, 1).Cells(xZeile, 9)).ClearContents
Else

Gruß
Franz

Anzeige
AW: Maske - Reihenfolge ändern
15.10.2015 09:52:21
Mike
Hallo Franz,
habe den Code geändert und bekomme den Fehler Variable nicht definiert... (xZeile = 2)
Private Sub ComboBox1_Click()
If ComboBox1.ListIndex = 0 Then
xZeile = 2
.Range(.Cells(xZeile, 1).Cells(xZeile, 10)).Copy
.Range(.Cells(xZeile + 1, 1).Cells(xZeile + 1, 10)).Insert Shift:=xlShiftDown
.Range(.Cells(xZeile, 1).Cells(xZeile, 10)).ClearContents
Else
Else
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
TextBox5 = ""
TextBox6 = ""
TextBox7 = ""
TextBox8 = ""
TextBox9 = ""
TextBox10 = ""
End If
End Sub
Gruß Mik

Anzeige
AW: Maske - Reihenfolge ändern
15.10.2015 11:54:24
fcs
Hallo Mik,
da du wohl mit der Option "Option Explicit" am ANfag des Modul arbeitest (was sinnvoll ist), müssen alle Variablen, die im Makro verwendet werden, in einer Dim-, Public- oder Private-Anweisung deklariert werden.
Außerdem hast du einen Teil meiner Lösung vergessen: Die Variable wks und die With-Konstruktion.
Gruß
Franz
Private Sub ComboBox1_Click()
Dim wks As Worksheet, xZeile As Long
Set wks = ActiveSheet
If ComboBox1.ListIndex = 0 Then
With wks
xZeile = 2
.Range(.Cells(xZeile, 1).Cells(xZeile, 10)).Copy
.Range(.Cells(xZeile + 1, 1).Cells(xZeile + 1, 10)).Insert Shift:=xlShiftDown
.Range(.Cells(xZeile, 1).Cells(xZeile, 10)).ClearContents
End With
Else
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
TextBox5 = ""
TextBox6 = ""
TextBox7 = ""
TextBox8 = ""
TextBox9 = ""
TextBox10 = ""
End If
End Sub

Anzeige
;

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Entdecke mehr
Finde genau, was du suchst

Die erweiterte Suchfunktion hilft dir, gezielt die besten Antworten zu finden

Suche nach den besten Antworten
Unsere beliebtesten Threads

Entdecke unsere meistgeklickten Beiträge in der Google Suche

Top 100 Threads jetzt ansehen
Anzeige