ich habe eine ListBox1, die ich mit nachstehendem Code befülle:
Sub ListBox1_fuellen()
Dim lRow As Long
Dim lastRow As Long
Dim objList As Object
Dim wsName As String
wsName = UserForm2.ComboBox1.Value
'Debug.Print wsName
Set objList = CreateObject("Scripting.dictionary")
UserForm2.ListBox1.Clear
UserForm2.ListBox1.ColumnCount = 11
UserForm2.ListBox1.ColumnWidths = "3,3cm;4,0cm;2,0cm;3,0cm;3,5cm;3,0cm;3,0cm;5,5cm;4,8cm;2, _
1cm;2,3cm"
'' A B C D E F G H I J _
K L M N O
With Sheets(wsName)
lastRow = .Range("A" & Sheets(wsName).Rows.Count).End(xlUp).Row
For lRow = 2 To lastRow
objList(lRow) = Array( _
.Cells(lRow, 1).Value, _
.Cells(lRow, 2).Value, _
.Cells(lRow, 3).Value, _
.Cells(lRow, 4).Value, _
.Cells(lRow, 5).Value, _
.Cells(lRow, 6).Value, _
.Cells(lRow, 7).Value, _
.Cells(lRow, 8).Value, _
.Cells(lRow, 9).Value, _
.Cells(lRow, 10).Value, _
Cells(lRow, 11).Value)
Next
End With
ListBox1.List = WorksheetFunction.Transpose(WorksheetFunction.Transpose(objList.items))
End Sub
Ich möchte aber gerne über die TextBox1 einen Suchbegriff eingeben und mittels Commandbutton1 die ListBox1 mit den gefundenen Werten befüllen. Hierzu habe ich bisher das nachstehende Makro:
Private Sub CommandButton1_Click()
Dim c As Range
Dim rngBereich As Range
Dim lngAnzahl As Long
Dim strFirst As String
Dim txtSearch As String
txtSearch = Me.TextBox1 'Suchbegriff
Me.ListBox1.Clear
Me.ListBox1.ColumnCount = 11
With Sheets("Tabelle1")
Set rngBereich = .Columns("A:K")
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)
ListBox1.List(lngAnzahl - 1, 8) = .Cells(c.Row, 9)
ListBox1.List(lngAnzahl - 1, 9) = .Cells(c.Row, 10)
' ListBox1.List(lngAnzahl - 1, 10) = .Cells(c.Row, 11) 'bei AddItem 11 Spalte _
nicht möglich
Set c = rngBereich.FindNext(c)
Loop While Not c Is Nothing And c.Address strFirst
End If
End With
End Sub
Könnt ihr mir bitte helfen, dass das Suchen mit mehr als 10 Spalten in Listbox möglich ist. Vielleicht kann man die beiden Makros irgendwie verbinden. Besten Dank für eure Hilfe.Gruss
Peter