Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1448to1452
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

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

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

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

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

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige