Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
980to984
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
980to984
980to984
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Suche in ListBox-Ausgabe ComboBox

Suche in ListBox-Ausgabe ComboBox
03.06.2008 09:38:00
Björn
Hallo,
habe mal wieder ein Problem mit VBA.
Ich habe eine Userform in der ich über eine TextBox Werte suchen möchte, die in Tabelle1 stehen. In den jeweiligen Zeilen stehen noch andere Daten, die in ComboBoxen ausgegeben werden sollen.
Das habe ich bis jetzt auch hinbekommen. Leider gefällt mir dies nicht. In der ersten ComboBox wird bei erneuter Suche auch alles ordentlich angezeigt. Jedoch steht bei der ComboBox2 und 3 jeweils der vorherige Wert drin und man muss immer erst klicken, damit man den aktuellen Wert angezeigt bekommt.
Kann mir jemand sagen, wie ich das weg bekomme?
Vielleicht kann mir auch jemand sagen, wie ich es hinbekomme, dass ich Werte in die Textbox eingebe und durch ENTER werden diese dann sofort gesucht, ohne dass ich den Suchen-Button anklicken muss.
Anbei eine Beispielmappe: https://www.herber.de/bbs/user/52780.xls
Björn

Private Sub CommandButton1_Click()
Dim rng As Range
Dim strFirst As String
Dim vtmp() As Long
Dim tntC As Integer
Dim IntC As Long
If Len(Trim(TextBox1)) = 0 Then Exit Sub
ComboBox1.Clear
For IntC = 1 To 10
Next
ReDim vtmp(0)
With Sheets("Tabelle1")
Set rng = .Range("A:H").Find(what:=TextBox1, lookat:=xlPart)
If Not rng Is Nothing Then
strFirst = rng.Address
Do
If Not (IsNumeric(Application.Match(rng.Row, vtmp, 0))) Then
ReDim Preserve vtmp(UBound(vtmp) + 1)
vtmp(UBound(vtmp)) = rng.Row
ComboBox1.AddItem .Cells(rng.Row, 2)
ComboBox2.AddItem .Cells(rng.Row, 6)
ComboBox3.AddItem .Cells(rng.Row, 8)
End If
Set rng = .Range("A:H").FindNext(rng)
Loop While Not rng Is Nothing And rng.Address  strFirst
End If
End With
If ComboBox1.ListCount > 0 Then
ComboBox1.ListIndex = 0
Else
ComboBox1.AddItem "Kein Eintrag!"
End If
If ComboBox2.ListCount > 0 Then
ComboBox2.ListIndex = 0
Else
ComboBox2.AddItem "Kein Eintrag!"
End If
If ComboBox3.ListCount > 0 Then
ComboBox3.ListIndex = 0
Else
ComboBox3.AddItem "Kein Eintrag!"
End If
Set rng = Nothing
End Sub


3
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Suche in ListBox-Ausgabe ComboBox
03.06.2008 09:52:28
Peter
Hallo Björn,
vielleicht hilft bereits ein ComboBox1, 2, 3.Clear um die neuen Werte anzuzeigen.
Gruß Peter

AW: Suche in ListBox-Ausgabe ComboBox
03.06.2008 10:14:00
Björn
Hallo Peter,
danke für den Tipp. Funktioniert jetzt wie ich es mir vorstelle.
Björn

AW: Alternative
03.06.2008 10:25:00
Chris
Servus Björn,
als Alternative, wenn der Inhalt der CB beibehalten werden soll:

Private Sub CommandButton1_Click()
Dim rng As Range
Dim strFirst As String
Dim vtmp() As Long
Dim tntC As Integer
Dim IntC As Long
If Len(Trim(TextBox1)) = 0 Then Exit Sub
ComboBox1.Clear
For IntC = 1 To 10
Next
ReDim vtmp(0)
With Sheets("Tabelle1")
Set rng = .Range("A:H").Find(what:=TextBox1, lookat:=xlPart)
If Not rng Is Nothing Then
strFirst = rng.Address
Do
If Not (IsNumeric(Application.Match(rng.Row, vtmp, 0))) Then
ReDim Preserve vtmp(UBound(vtmp) + 1)
vtmp(UBound(vtmp)) = rng.Row
ComboBox1.AddItem .Cells(rng.Row, 2)
ComboBox2.AddItem .Cells(rng.Row, 6)
ComboBox3.AddItem .Cells(rng.Row, 8)
End If
Set rng = .Range("A:H").FindNext(rng)
Loop While Not rng Is Nothing And rng.Address  strFirst
End If
End With
If ComboBox1.ListCount > 0 Then
ComboBox1.ListIndex = 0
Else
ComboBox1.AddItem "Kein Eintrag!"
End If
With ComboBox2
If .ListCount > 0 Then
.ListIndex = .ListCount - 1
If .Value = "" Then
.Value = "kein Eintrag"
End If
Else
.Value = "kein Eintrag"
End If
End With
With ComboBox3
If .ListCount > 0 Then
.ListIndex = .ListCount - 1
If .Value = "" Then
.Value = "kein Eintrag"
End If
Else
.Value = "kein Eintrag"
End If
End With
Set rng = Nothing
End Sub


Gruß
Chris

Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige