AW: Suchfunktion
17.04.2006 04:17:48
Heinz
Hallo Hassan
Hier ein Code der Deinen Vorstellungen am nächsten kommt.
Auswahl aus gesamten Daten der Spalte A (Land), dann Auswahl
der gefilterten Daten aus Spalte B (Plz) und Anzeige nach Auswahl (Prod)
ebenfalls gefilter aus Spalte C.
Dim strLand, strPlz, strProd, strAdr As String
Private Sub UserForm_Activate()
'Füllt die Boxen beim Starten der UF mit allen Daten
'-----------Liste in ListBox1,2,3 hinzufügen--------
For Zähler = 0 To ListBox1.ListCount
If ListBox1.ListCount >= 1 Then
If ListBox1.ListIndex = -1 Then
ListBox1.ListIndex = ListBox1.ListCount - 1
End If
ListBox1.RemoveItem (ListBox1.ListIndex)
End If
Next Zähler
For Zähler = 0 To ListBox2.ListCount
If ListBox2.ListCount >= 1 Then
If ListBox2.ListIndex = -1 Then
ListBox2.ListIndex = ListBox2.ListCount - 1
End If
ListBox2.RemoveItem (ListBox2.ListIndex)
End If
Next Zähler
For Zähler = 0 To ListBox3.ListCount
If ListBox3.ListCount >= 1 Then
If ListBox3.ListIndex = -1 Then
ListBox3.ListIndex = ListBox3.ListCount - 1
End If
ListBox3.RemoveItem (ListBox3.ListIndex)
End If
Next Zähler
Set aktuelleZelle = Worksheets(2).Range("A2")
Do While Not IsEmpty(aktuelleZelle)
Set nächsteZelle = aktuelleZelle.Offset(1, 0)
ListBox1.AddItem aktuelleZelle.Offset(0, 0)
ListBox2.AddItem aktuelleZelle.Offset(0, 1)
ListBox3.AddItem aktuelleZelle.Offset(0, 2)
Set aktuelleZelle = nächsteZelle
Loop
TextBox1.Locked = True
End Sub
Private Sub ListBox1_Click()
'Füllt die Box2 mit allen Daten nach Auswahl aus Box1
'-----------Liste in ListBox2 hinzufügen-------------
strLand = ListBox1.Text
For Zähler = 0 To ListBox2.ListCount
If ListBox2.ListCount >= 1 Then
If ListBox2.ListIndex = -1 Then
ListBox2.ListIndex = ListBox2.ListCount - 1
End If
ListBox2.RemoveItem (ListBox2.ListIndex)
End If
Next Zähler
For Zähler = 0 To ListBox3.ListCount
If ListBox3.ListCount >= 1 Then
If ListBox3.ListIndex = -1 Then
ListBox3.ListIndex = ListBox3.ListCount - 1
End If
ListBox3.RemoveItem (ListBox3.ListIndex)
End If
Next Zähler
Set aktuelleZelle = Worksheets(2).Range("A2")
Do While Not IsEmpty(aktuelleZelle)
Set nächsteZelle = aktuelleZelle.Offset(1, 0)
If aktuelleZelle = strLand Then
ListBox2.AddItem aktuelleZelle.Offset(0, 1)
ListBox3.AddItem aktuelleZelle.Offset(0, 2)
End If
Set aktuelleZelle = nächsteZelle
Loop
TextBox1.Text = ""
End Sub
Private Sub ListBox2_Click()
'Füllt die Box3 mit allen Daten nach Auswahl aus Box2
'-----------Liste in ListBox3 hinzufügen-------------
strPlz = ListBox2.Text
TextBox1.Text = ""
For Zähler = 0 To ListBox3.ListCount
If ListBox3.ListCount >= 1 Then
If ListBox3.ListIndex = -1 Then
ListBox3.ListIndex = ListBox3.ListCount - 1
End If
ListBox3.RemoveItem (ListBox3.ListIndex)
End If
Next Zähler
Set aktuelleZelle = Worksheets(2).Range("A2")
Do While Not IsEmpty(aktuelleZelle)
Set nächsteZelle = aktuelleZelle.Offset(1, 0)
If aktuelleZelle.Offset(0, 1) = CStr(strPlz) Then
ListBox3.AddItem aktuelleZelle.Offset(0, 2)
End If
Set aktuelleZelle = nächsteZelle
Loop
TextBox1.Text = ""
End Sub
Private Sub ListBox3_Click()
'Füllt die TextBox1 mit Text nach Auswahl aus Box3
'-----------Liste in ListBox3 hinzufügen----------
strProd = ListBox3.Text
Set aktuelleZelle = Worksheets(2).Range("A2")
Do While Not IsEmpty(aktuelleZelle)
Set nächsteZelle = aktuelleZelle.Offset(1, 0)
If aktuelleZelle.Offset(0, 2) = strProd Then
strAdr = aktuelleZelle.Offset(0, 3)
End If
Set aktuelleZelle = nächsteZelle
Loop
TextBox1.Text = strAdr
End Sub
Wünsch' Dir noch schöne Ostern und mir ev. Rückmeldung
lg.
Heinz