ich habe ein Problem mit dem sortiert einlesen.
In der ComboBox wird immer eine leere Zeile zu Anfang angezeigt.
Kann die ComboBox auch ohne diese leere gefüllt werden?
Danke!
Gruß
Ludmila
Musterdatei:
https://www.herber.de/bbs/user/103029.xlsm
Nachfolgender Code wird verwendet:
Option Explicit
Dim loEnde As Long
Dim ii As Long
Private Sub ComboBox1_Change()
Dim StListe() As String
On Error Resume Next
ComboBox2.Clear
TextBox1.Text = ""
With Sheets("Tabelle1")
loEnde = .Cells(Rows.Count, 2).End(xlUp).Row
ReDim Preserve StListe(2 To loEnde)
For ii = 2 To loEnde
If Not IsEmpty(.Cells(ii, 2)) And .Cells(ii, 2) = ComboBox1.Value Then
StListe(ii) = .Cells(ii, 8)
End If
Next ii
Sort_Z_A StListe, LBound(StListe), UBound(StListe)
ComboBox2.AddItem StListe(1)
For ii = 2 To loEnde
If StListe(ii) StListe(ii - 1) Then ComboBox2.AddItem StListe(ii)
Next ii
End With
txtr.SetFocus
End Sub
Private Sub ComboBox2_Change()
With Sheets("Tabelle1")
For ii = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
If .Cells(ii, 2) = ComboBox1.Value And .Cells(ii, 8) = ComboBox2.Value Then
TextBox1.Text = .Cells(ii, 7).Value
Exit For
End If
Next ii
End With
txtr.SetFocus
End Sub
Private Sub UserForm_Initialize()
Dim StListe() As String
On Error Resume Next
With Sheets("Tabelle1")
loEnde = .Cells(Rows.Count, 2).End(xlUp).Row
ReDim Preserve StListe(2 To loEnde)
For ii = 2 To loEnde
StListe(ii) = .Cells(ii, 2)
Next ii
Sort_Z_A StListe, LBound(StListe), UBound(StListe)
ComboBox1.AddItem StListe(1)
For ii = 2 To loEnde
If StListe(ii) StListe(ii - 1) Then ComboBox1.AddItem StListe(ii)
Next ii
ComboBox1.ListIndex = -1
End With
End Sub
in Modul
Public Sub Sort_Z_A(SortArray, L, R)
' von GerdZ Herber.de
Dim I, J, x, y
I = L
J = R
x = SortArray((L + R) / 2)
While (I L)
J = J - 1
Wend
If (I
Public Sub Sort_A_Z(SortArray, L, R)
' von GerdZ Herber.de
Dim I, J, x, y
I = L
J = R
x = SortArray((L + R) / 2)
While (I x And I SortArray(J) And J > L)
J = J - 1
Wend
If (I