AW: Frage: bis 40 Zeilen in Tabelle per Userform ändern?
19.12.2019 00:14:38
Werner
Hallo,
das hier:
2. Wenn eine Nummer eingegeben wird und die Datensätze angezeigt werden und ich dann Speichern klicke kommt ebenfalls eine Fehlermeldung.
Welche Fehlermeldung denn und in welcher Codezeile?
Ich vermute mal, dass du meinst es kommt eine Fehlermeldung wenn kein Eintrag in der Listbox ausgewählt ist und du dann den Button klickst.
Wenn ja dann so:
Private Sub CommandButton1_Click()
Dim suche As Range, x As Long
If Me.ListBox1.ListIndex > -1 Then
x = ListBox1.List(ListBox1.ListCount - 1)
With ListBox1
Set suche = Sheets("BESTAND").Columns(1).Find(.Column(0, .ListIndex))
End With
With Sheets("BESTAND")
If Not suche Is Nothing Then
.Cells(suche.Row, 1) = TextBox2
.Cells(suche.Row, 8) = TextBox3
.Cells(suche.Row, 9) = TextBox4
.Cells(suche.Row, 10) = TextBox5
.Cells(suche.Row, 11) = TextBox6
End If
End With
Me.ListBox1.Clear
Call TextBox1_AfterUpdate
End If
Set suche = Nothing
End Sub
Und Meldung wenn die Nummer nicht vorhanden ist:
Private Sub TextBox1_AfterUpdate()
Dim boVorhanden As Boolean, ws As Worksheet
Dim zeile As Long, letzte As Long
Set ws = ThisWorkbook.Sheets("BESTAND")
letzte = ws.Cells(Rows.Count, 6).End(xlUp).Row
With ListBox1
.ColumnCount = 5
.ColumnWidths = "3cm;3cm;3cm;3cm;3cm"
End With
With ws
For zeile = 2 To letzte
If CLng(.Cells(zeile, 6)) = CLng(TextBox1) Then
boVorhanden = True
ListBox1.AddItem
ListBox1.List(ListBox1.ListCount - 1, 0) = .Cells(zeile, 1)
ListBox1.List(ListBox1.ListCount - 1, 1) = .Cells(zeile, 8)
ListBox1.List(ListBox1.ListCount - 1, 2) = .Cells(zeile, 9)
ListBox1.List(ListBox1.ListCount - 1, 3) = .Cells(zeile, 10)
ListBox1.List(ListBox1.ListCount - 1, 4) = .Cells(zeile, 11)
End If
Next
End With
If Not boVorhanden Then
Me.ListBox1.Clear
MsgBox "Die eingegebene Nummer ist nicht vorhanden."
End If
Set ws = Nothing
End Sub
Gruß Werner