AW: Listbox füllen ohne Duplikaten und leerzelle
18.11.2007 22:38:00
Karel
Hallo Gerd,
Benutzen deine variante, ihr liefert kein Fehler bei eingabe in suchfeld (bei unbekannte werten)
habe noch eine Fragen, wie kan man beim öffnen von Userform, die Listbox direkt fullen und sortiert anzeigen.
Sortier makro hab ich und Funktioniert auch wenn ich im Textfeld buchstabe eingeben.
Private Sub TextBox1_Change()
Dim var As Variant, arr() As Variant, arr2() As Variant
Dim index As Long, iCount As Long, X As Long
X = Sheets("Tabelle1").Cells(Rows.Count, "C").End(xlUp).Row
var = Sheets("Tabelle1").Range("C8:C" & X).SpecialCells(xlCellTypeConstants)
ReDim arr(0)
arr(0) = "#"
For iCount = 1 To UBound(var)
If Not IsNumeric(Application.Match(var(iCount, 1), arr, 0)) Then
ReDim Preserve arr(IIf(arr(0) = "#", 0, UBound(arr) + 1))
arr(UBound(arr)) = var(iCount, 1)
End If
Next
ListBox1.Clear
If TextBox1.Value = "" Then
ListBox1.List = arr
Exit Sub
End If
iCount = 0
ReDim arr2(0)
arr2(0) = " "
For index = 0 To UBound(arr)
If LCase(Left(arr(index), Len(TextBox1))) = LCase(TextBox1) Then
ReDim Preserve arr2(iCount)
arr2(iCount) = arr(index)
iCount = iCount + 1
End If
Next
ListBox1.List = arr2
Call Sortieren
End Sub
_______________________________________________________________
Sub Sortieren()
Dim Letzter As Integer, Naechster As Integer
Dim i As String
With ListBox1
For Letzter = 0 To .ListCount - 1
For Naechster = Letzter + 1 To .ListCount - 1
If .List(Letzter) > .List(Naechster) Then
i = .List(Letzter)
.List(Letzter) = .List(Naechster)
.List(Naechster) = i
End If
Next Naechster
Next Letzter
End With
End Sub
und kannst du mir diese anschnitt erlautern
For iCount = 1 To UBound(var)
If Not IsNumeric(Application.Match(var(iCount, 1), arr, 0)) Then
ReDim Preserve arr(IIf(arr(0) = "#", 0, UBound(arr) + 1))
arr(UBound(arr)) = var(iCount, 1)
Grusse
Karel