11 spaltige Listbox ?
15.02.2004 14:16:30
Jörg
ich möchte anhand eines gesuchten Begriffs eine Listbox füllen.
Sofern ich diese Listbox mit max. 10 Spalten verwende, ist alles OK. Sobald ich Nun möchte ich jedoch z.B. 12 Spalten verwenden möchte, funktionierts nicht mehr. Habt Ihr einen Tip zur Lösung.
Private Sub UserForm_Initialize()
Dim Found As Range
Dim FirstAddress As String, Search As String
Dim LoLetzte As Long, LoI As Long
Dim ZuDurchsuchendesBlatt As Variant, ZuDurchsuchendeSpalte As Variant
Dim Suchbeginn As Variant, Suchbereich As Variant, Suchende As Variant
ZuDurchsuchendesBlatt = UserForm3.ComboBox1.Value
ZuDurchsuchendeSpalte = Application.WorksheetFunction _
.Match(UserForm3.ComboBox2.Value, Sheets(ZuDurchsuchendesBlatt).Range("2:2"), 0)
Suchende = Chr(ZuDurchsuchendeSpalte + 64) & 65536
If ["Suchende"] = "" Then
LoLetzte = ["Suchende"].End(xlUp).Row
Else
LoLetzte = 65536
End If
Suchbereich = Chr(ZuDurchsuchendeSpalte + 64) & 3 & ":" & Chr(ZuDurchsuchendeSpalte + 64) & LoLetzte
Suchbeginn = Chr(ZuDurchsuchendeSpalte + 64) & 3
Search = UserForm3.TextBox1.Value 'InputBox("Welcher Begriff wird gesucht ?")
If Search = "" Then Exit Sub
With ListBox1
With Sheets(ZuDurchsuchendesBlatt).Range(Suchbereich)
Set Found = .Find(Search, Sheets(ZuDurchsuchendesBlatt).Range(Suchbeginn), , xlPart, , xlNext)
If Found Is Nothing Then Exit Sub 'falls nix gefunden wird sub verlassen
FirstAddress = Found.Address
ListBox1.AddItem Format(Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 2), "0000#") ' Spalte B
ListBox1.List(LoI, 1) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 3) ' Spalte C
ListBox1.List(LoI, 2) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 4) ' Spalte D
ListBox1.List(LoI, 3) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 5) ' Spalte E
ListBox1.List(LoI, 4) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 6) ' Spalte F
ListBox1.List(LoI, 5) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 7) ' Spalte G
ListBox1.List(LoI, 6) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 8) ' Spalte H
ListBox1.List(LoI, 7) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 9) ' Spalte I
ListBox1.List(LoI, 8) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 10) ' Spalte J
ListBox1.List(LoI, 9) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 11) ' Spalte K
'Ab hier funktionierts nicht mehr
ListBox1.List(LoI, 10) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 12) ' Spalte L
ListBox1.List(LoI, 11) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 13) ' Spalte M
ListBox1.List(LoI, 12) = Found.Row
LoI = LoI + 1
Do
Set Found = .FindNext(Found)
If Found.Address = FirstAddress Then Exit Sub
ListBox1.AddItem Format(Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 2), "0000#") ' Spalte B
ListBox1.List(LoI, 1) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 3) ' Spalte C
ListBox1.List(LoI, 2) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 4) ' Spalte D
ListBox1.List(LoI, 3) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 5) ' Spalte E
ListBox1.List(LoI, 4) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 6) ' Spalte F
ListBox1.List(LoI, 5) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 7) ' Spalte G
ListBox1.List(LoI, 6) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 8) ' Spalte H
ListBox1.List(LoI, 7) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 9) ' Spalte I
ListBox1.List(LoI, 8) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 10) ' Spalte J
ListBox1.List(LoI, 9) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 11) ' Spalte K
'Ab hier funktionierts nicht mehr
ListBox1.List(LoI, 10) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 12) ' Spalte L
ListBox1.List(LoI, 11) = Sheets(ZuDurchsuchendesBlatt).Cells(Found.Row, 13) ' Spalte M
ListBox1.List(LoI, 12) = Found.Row
If Found.Row = LoLetzte Then Exit Sub
LoI = LoI + 1
Loop While Not Found Is Nothing
End With
End Sub