AW: VBA suchen und in Listbox ausgeben
31.07.2017 08:16:57
Markus
Hallo Tom,
vielen Dank, genau so wollte ich das haben!
Aber warum sollte ich es auf eine Suchspalte begrenzen?
Ich müsste sogar in den Spalten A bis H suchen und hab den Code umgeschrieben.
Dann findet es es zwar die Zeilen und schreibt sie in die Listbox aber die letzten beiden Spalten werden nicht angezeigt, was habe ich falsch gemacht?
Option Explicit
' Steuerelementer des UF
' Textbox - Name = txtSearch
' Listbox - Name = Listbox1
' CheckBox - Name = chkPart
' CheckBox - Name = chkCase
' CommandButton - Name = cmdSearch
' CommandButton - Name = cmdClose
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub cmdSearch_Click()
Dim c As Range
Dim rngBereich As Range
Dim lngAnzahl As Long
Dim strFirst As String
With Sheets("Daten")
Set rngBereich = .Columns("A:H")
Set c = rngBereich.Find(txtSearch, LookIn:=xlValues, lookat:=xlPart)
If Not c Is Nothing Then
strFirst = c.Address
Do
ListBox1.AddItem .Cells(c.Row, 1)
lngAnzahl = ListBox1.ListCount
ListBox1.List(lngAnzahl - 1, 1) = .Cells(c.Row, 2)
ListBox1.List(lngAnzahl - 1, 2) = .Cells(c.Row, 3)
ListBox1.List(lngAnzahl - 1, 3) = .Cells(c.Row, 4)
ListBox1.List(lngAnzahl - 1, 4) = .Cells(c.Row, 5)
ListBox1.List(lngAnzahl - 1, 5) = .Cells(c.Row, 6)
ListBox1.List(lngAnzahl - 1, 6) = .Cells(c.Row, 7)
ListBox1.List(lngAnzahl - 1, 7) = .Cells(c.Row, 8)
Set c = rngBereich.FindNext(c)
Loop While Not c Is Nothing And c.Address strFirst
End If
End With
End Sub
Private Sub TextBox1_Change()
End Sub
'
Private Sub txtSearch_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
' If KeyCode = 13 Then cmdSearch_Click
'End Sub
Private Sub UserForm_Initialize()
With ListBox1
.Clear
.ColumnCount = 6
.ColumnWidths = "75;75;75;75;75;75"
End With
End Sub