ich habe auf UF1 drei Comboboxen, die mir nach Auswahl, die Listbox1 und verschiedene Textboxen füllt.
Wenn ich zuerst Combobox1 anklicke steht dann ein Wert zur Auswahl und die dazugehörigen Daten werden in Listbox1 geschrieben, wenn ich allerdings Combobox 2 od 3 anklicke bleibt der Wert in CB1 stehen.
Frage: Wie kann ich es anstellen, dass bei Auswahl CB1 die CBen 2 & 3 und entsprechenden Textboxen geleert werden? Bei CB 2 entsprechend CB 1 & 3 etc. Die Listbox wird zuverlässig vor Neueintrag geleert.
Bei: Combobox2.clear wird bei "Suche = ComboBox2.List(ComboBox2.ListIndex, 0)" gemeckert!
Vielen Dank im voraus
LG Ingo
Private Sub ComboBox1_Change() 'Klasse
Dim K As Long
Dim N As Long
Dim Suche As String
Dim Stunden As Double
Suche = ComboBox1.List(ComboBox1.ListIndex, 0)
With Worksheets("AlleDaten")
ListBox1.Clear
For K = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
If Suche = .Cells(K, 1).Value Then
ListBox1.AddItem
N = ListBox1.ListCount - 1
ListBox1.List(N, 0) = .Cells(K, 1).Value
ListBox1.List(N, 1) = .Cells(K, 2).Value
ListBox1.List(N, 2) = .Cells(K, 3).Value
ListBox1.List(N, 3) = Format(.Cells(K, 4).Value, "##0.00")
ListBox1.List(N, 4) = Format(.Cells(K, 5).Value, "##0.00")
ListBox1.List(N, 5) = .Cells(K, 6).Value
'ListBox1.List(N, 5) = Format(.Cells(K, 6).Value, "##0.00")
ListBox1.List(N, 6) = K
Stunden = Format(Stunden + .Cells(K, 4).Value, "##0.00")
End If
Next
TextBox15.Value = Stunden
End With
End Sub
Private Sub ComboBox2_Change() 'Fach
Dim K As Long
Dim N As Long
Dim Suche As String
Dim Stunden As Double
Suche = ComboBox2.List(ComboBox2.ListIndex, 0)
With Worksheets("AlleDaten")
ListBox1.Clear
For K = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
If Suche = .Cells(K, 2).Value Then
ListBox1.AddItem
N = ListBox1.ListCount - 1
ListBox1.List(N, 0) = .Cells(K, 1).Value
ListBox1.List(N, 1) = .Cells(K, 2).Value
ListBox1.List(N, 2) = .Cells(K, 3).Value
ListBox1.List(N, 3) = Format(.Cells(K, 4).Value, "##0.00")
ListBox1.List(N, 4) = Format(.Cells(K, 5).Value, "##0.00")
ListBox1.List(N, 5) = .Cells(K, 6).Value
'ListBox1.List(N, 5) = Format(.Cells(K, 6).Value, "##0.00")
ListBox1.List(N, 6) = K
Stunden = Format(Stunden + .Cells(K, 4).Value, "##0.00")
End If
Next
TextBox15.Value = Stunden
End With
End Sub
Private Sub ComboBox3_Change() 'Name
Dim K As Long
Dim N As Long
Dim Suche As String
Dim Stunden As Double
With Me
Sheets("Namen").Activate
Range("a:a").Select
Selection.Find(what:=.ComboBox3.Value, _
after:=ActiveCell, _
LookIn:=xlFormulas, lookat:=xlPart, _
searchorder:=xlByRows, searchdirection:=xlNext, _
MatchCase:=False).Activate
.TextBox10.Value = Round(ActiveCell.Offset(0, 5).Value, "2") ' Altersentlastung
.TextBox11.Value = Round(ActiveCell.Offset(0, 6).Value, "2") ' Entlast.Beh
.TextBox12.Value = Round(ActiveCell.Offset(0, 7).Value, "2") ' Entl.Vorgriff
.TextBox9.Value = Round(ActiveCell.Offset(0, 8).Value, "2") ' Entl SFD
.TextBox14.Value = Round(ActiveCell.Offset(0, 2).Value, "2") 'Deputat
.TextBox7.Value = Round(ActiveCell.Offset(0, 10).Value, "2") 'Summe Entl
.TextBox8.Value = Round(ActiveCell.Offset(0, 9).Value, "2") 'Entl Std Konto
.TextBox13.Value = Round(ActiveCell.Offset(0, 11).Value, "1") 'Bez Std
'TextBox34.Value = Round(ActiveCell.Offset(0, 34).Value, "2")
End With
Suche = ComboBox3.List(ComboBox3.ListIndex, 0)
With Worksheets("AlleDaten")
ListBox1.Clear
For K = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
If Suche = .Cells(K, 3).Value Then
ListBox1.AddItem
N = ListBox1.ListCount - 1
ListBox1.List(N, 0) = .Cells(K, 1).Value
ListBox1.List(N, 1) = .Cells(K, 2).Value
ListBox1.List(N, 2) = .Cells(K, 3).Value
ListBox1.List(N, 3) = Format(.Cells(K, 4).Value, "##0.00")
ListBox1.List(N, 4) = Format(.Cells(K, 5).Value, "##0.00")
ListBox1.List(N, 5) = .Cells(K, 6).Value
'ListBox1.List(N, 5) = Format(.Cells(K, 6).Value, "##0.00")
ListBox1.List(N, 6) = K
Stunden = Format(Stunden + .Cells(K, 4).Value, "##0.00")
End If
Next
TextBox15.Value = Stunden
'TextBox32.Text = Worksheets("Namen").Cells(ComboBox3.ListIndex + 10)
End With
'On Error GoTo Fehler
'Fehler:
'MsgBox "Dieser Name ist nicht in Tabelle NAMEN vorhanden, oder muss bearbeitet werden!"
End Sub