AW: List-/Text-/Combobox
03.02.2016 09:32:01
fcs
Hallo Wlo,
probiere mal, ob der nachfolgende angepasste Code für das Userform für deine Zwecke passt.
Gruß
Franz
Option Explicit
Private bolClickListbox As Boolean
Sub prcFillListbox1()
Dim lSpalte As Long
Dim lZeile As Long
Dim WkSh As Worksheet
ListBox1.Clear
If sSpalte = "" Then
MsgBox "Bitte erst ein Land auswählen", _
48, " Prüfung Auswahl Land"
Exit Sub
Else
lSpalte = Asc(sSpalte) - 64
End If
Set WkSh = Worksheets("Tabelle1")
With WkSh
For lZeile = 2 To .Cells(.Rows.Count, lSpalte).End(xlUp).Row
If .Cells(lZeile, lSpalte).Value <> "" Then
ListBox1.AddItem .Cells(lZeile, lSpalte).Text
End If
Next lZeile
End With
'ListBox1.AddItem WkSh.Cells(lZeile, sSpalte)
Call Sortieren
End Sub
Private Sub UserForm_Initialize()
With Me.ComboBox1
.AddItem ""
.AddItem "Schweiz"
.AddItem "Deutschland"
.AddItem "Österreich"
.ListIndex = 0
End With
End Sub
Private Sub ComboBox1_Change()
Cells(3, 6).Value = ComboBox1.Value
If Me.ComboBox1.ListIndex > 0 Then
sSpalte = Chr(Me.ComboBox1.ListIndex + 64)
Call prcFillListbox1
Else
sSpalte = ""
Me.ListBox1.Clear
End If
End Sub
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
bolClickListbox = True
With Me.ListBox1
If .ListIndex <> -1 Then
Me.TextBox1.Value = .List(.ListIndex, 0)
End If
End With
bolClickListbox = False
End Sub
Private Sub TextBox1_Change()
Dim iZeichen As Integer
Dim WkSh As Worksheet
Dim lZeile As Long
Dim lSpalte As Long
If bolClickListbox = True Then Exit Sub
If sSpalte = "" Then
MsgBox "Bitte erst ein Land auswählen", _
48, " Prüfung Auswahl Land"
Exit Sub
Else
lSpalte = Asc(sSpalte) - 64
End If
Set WkSh = Worksheets("Tabelle1")
Me.ListBox1.Clear
With WkSh
For lZeile = 2 To .Cells(.Rows.Count, lSpalte).End(xlUp).Row
If .Cells(lZeile, lSpalte).Value <> "" Then
If Len(Me.TextBox1.Value) <> 0 Then
If Left(LCase(.Cells(lZeile, lSpalte).Value), Len(Me.TextBox1.Value)) = _
LCase(Me.TextBox1.Value) Then
If WorksheetFunction.CountIf(.Range(.Cells(1, lSpalte), .Cells(lZeile, lSpalte)) _
, _
.Cells(lZeile, lSpalte)) = 1 Then _
ListBox1.AddItem .Cells(lZeile, lSpalte).Text
End If
End If
End If
Next lZeile
End With
'ListBox1.AddItem WkSh.Cells(lZeile, sSpalte)
Call Sortieren
End Sub
Private Sub UserForm_Activate()
Dim iZeichen As Integer
Dim WkSh As Worksheet
Dim lZeile As Long
Call ComboBox1_Change
End Sub
Sub Sortieren()
Dim Letzter As Integer
Dim Naechster As Integer
Dim sTmp As String
With UserForm1.ListBox1
For Letzter = 0 To .ListCount - 1
For Naechster = Letzter + 1 To .ListCount - 1
If .List(Letzter) > .List(Naechster) Then
sTmp = .List(Letzter)
.List(Letzter) = .List(Naechster)
.List(Naechster) = sTmp
End If
Next Naechster
Next Letzter
End With
End Sub