AW: Userform - Geänderte/Ergänzte Daten in neues Tabellenblatt
21.11.2019 22:53:37
Piet
Hallo Alex
die einfachste Möglichkeit ist, in der Datentabelle eine zweite Tabelle "Änderungen" einzufügen und dort alle Änderungen mit abzuspeichern. Den Code habe ich dafür mal geaendert.
mfg Piet
Private Sub Button_Abbrechen_Click()
ActiveWorkbook.Close
Unload Me
End Sub
Private Sub Button_ändern_Click()
Dim lngZeile As Long
Dim i As Long
'Zuerst prüfen ob ein Datensatz im Listenfeld markiert ist
If Me.ListBox1.ListIndex >= 0 Then
'With tbl_Artikel 'Internes Inventur Blatt
With ActiveSheet 'geöffnete Inventur Datei!
lngZeile = .Cells(Rows.Count, 1).End(xlUp).Row
'Datensatz in tbl_Artikel suchen
For i = 1 To lngZeile + 1
If .Cells(i, 1).Text = CStr(Me.ListBox1.Value) Then Exit For
Next i
If i 0 Then
Me.ListBox1.AddItem .Cells(lngZeile, 1).Text 'Daten aus Zellen holen und in _
ListBox anzeigen
Me.ListBox1.Column(1, i) = .Cells(lngZeile, 2).Value
Me.ListBox1.Column(2, i) = .Cells(lngZeile, 6).Value
Me.ListBox1.Column(3, i) = .Cells(lngZeile, 4).Value
Me.ListBox1.Column(4, i) = .Cells(lngZeile, 20).Text
Me.ListBox1.Column(5, i) = .Cells(lngZeile, 21).Text
Me.ListBox1.Column(6, i) = .Cells(lngZeile, 22).Value
Me.ListBox1.Column(7, i) = .Cells(lngZeile, 17).Value
Me.ListBox1.Column(8, i) = .Cells(lngZeile, 18).Value
Me.ListBox1.Column(9, i) = lngZeile
i = i + 1
End If
Next lngZeile
End With
End Sub
Private Sub Button_Suchen2_Click()
Dim lngZeile As Long
Dim lngZeileMx As Long
Dim i As Integer
Me.ListBox1.Clear
With ActiveSheet
lngZeileMax = .Cells(.Rows.Count, 1).End(xlUp).Row
For lngZeile = 1 To lngZeileMax
If InStr(LCase(.Cells(lngZeile, 2).Text), _
LCase(Me.TextBox2.Text)) > 0 Then
Me.ListBox1.AddItem .Cells(lngZeile, 1).Text
Me.ListBox1.Column(1, i) = .Cells(lngZeile, 2).Value
Me.ListBox1.Column(2, i) = .Cells(lngZeile, 6).Value
Me.ListBox1.Column(3, i) = .Cells(lngZeile, 4).Value
Me.ListBox1.Column(4, i) = .Cells(lngZeile, 20).Text
Me.ListBox1.Column(5, i) = .Cells(lngZeile, 21).Text
Me.ListBox1.Column(6, i) = .Cells(lngZeile, 22).Value
Me.ListBox1.Column(7, i) = .Cells(lngZeile, 17).Value
Me.ListBox1.Column(8, i) = .Cells(lngZeile, 18).Value
Me.ListBox1.Column(9, i) = lngZeile
i = i + 1
End If
Next lngZeile
End With
End Sub
Private Sub ListBox1_Click() 'Per Klick die Daten aus der ListBox in das Formular übertagen
Dim lngZeile As Long
Dim i As Long
lngZeile = Me.ListBox1.Column(9, Me.ListBox1.ListIndex)
'With tbl_Artikel 'Internes Inventur Blatt
With ActiveSheet 'geöffnete Inventur Datei!
For i = 1 To 8
Me.Controls("TextBox" & i).Text = .Cells(lngZeile, i).Text
Next i
Me.Controls("TextBox6").Value = .Cells(lngZeile, 6).Value
Me.Controls("TextBox17").Value = .Cells(lngZeile, 17).Value
Me.Controls("TextBox18").Value = .Cells(lngZeile, 18).Value
'Aktuelles Datum / Zeit / Aktiver Benutzer automatisch in Formular einfügen
Die_Inventur.TextBox20 = Date
Die_Inventur.TextBox21 = Time
Die_Inventur.TextBox22 = Environ("username")
End With
End Sub
Private Sub UserForm_Initialize()
'ListBox erstellen
With Me.ListBox1
.ColumnCount = 9
.ColumnWidths = "120;180;60;70;90;80;93;60;50"
.TextAlign = fmTextAlignCenter
End With
'Cursor standardmäßig in die erste Textbox setzen
Me.TextBox1.SetFocus
Me.Caption = ActiveWindow.Caption
End Sub