Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1192to1196
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Reihenfolge in ComboBox Liste

Reihenfolge in ComboBox Liste
Bernd
Hallo Excelfreunde,
folgender Code füllt eine ComboBox mit Werten.
Private Sub UserForm_Initialize()
Dim ixCol As Integer
Dim ixRow As Long
Dim ixRowS As Long
Dim ixRowE As Long
Dim ixList As Integer
ixList = 0
ixCol = 30                ' Suchspalte (H = 8)
ixRowS = 2                ' ab Starreihe
ixRowE = 1000             ' bis Schlussreihe
ComboBox1.Clear
ComboBox1.SetFocus
ComboBox1.AddItem ActiveSheet.Cells(ixRowS, ixCol).Value
For ixRow = ixRowS + 1 To ixRowE
If Not IsEmpty(ActiveSheet.Cells(ixRow, ixCol).Value) Then
For ixList = 0 To ComboBox1.ListCount - 1
If UCase(ComboBox1.List(ixList)) > UCase(ActiveSheet.Cells(ixRow, ixCol).Value)  _
Then
ComboBox1.AddItem ActiveSheet.Cells(ixRow, ixCol).Value, ixList
Exit For
End If
Next ixList
If ixList = ComboBox1.ListCount Then
If UCase(ComboBox1.List(ixList - 1)) 
Diese Werte sollen aufsteigend angezeigt werden. Leider sieht die Reihenfolge aber so aus
1
101
11
2
22
240
25
3
31
32
usw.

Wie muss der Code geändert werden, damit es wirklich aufsteigend angezeigt wird? Wäre für Hilfe sehr dankbar!
Gruß Bernd

3
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Benutzer
Anzeige
AW: Reihenfolge in ComboBox Liste
14.01.2011 10:10:18
Rudi
Hallo,
klar! Du sortierst ja auch Text anstatt Zahlen.
Teste mal:
If CInt</b>(ComboBox1.List(ixList)) > CInt</b>(ActiveSheet.Cells(ixRow, ixCol).Value) Then
Gruß
Rudi
AW: Reihenfolge in ComboBox Liste
14.01.2011 10:50:50
Bernd
Hallo Rudi,
hat nicht funktioniert. Aber ich habe jetzt das UCase ganz heraus genommen und "größer als" und "kleiner als" in Beiden Zeilen vertauscht. Hat geklappt.
Aber ohne deinen Hinweis wäre ich nicht weiter gekommen. Danke!
Gruß Bernd
AW: Reihenfolge in ComboBox Liste
14.01.2011 10:11:51
Beverly
Hi Bernd,
versuche es mal so:
Private Sub UserForm_Initialize()
Dim ixCol As Integer
Dim ixRow As Long
Dim ixRowS As Long
Dim ixRowE As Long
Dim arrWerte()
ixList = 0
ixCol = 30                ' Suchspalte (H = 8)
ixRowS = 2                ' ab Starreihe
' bis Schlussreihe
ixRowE = IIf(IsEmpty(Cells(Rows.Count, ixCol)), Cells(Rows.Count, ixCol).End(xlUp).Row,  _
Rows.Count)
ComboBox1.Clear
ComboBox1.SetFocus
arrWerte = Application.Transpose(Range(Cells(ixRowS, ixCol), Cells(ixRowE, ixCol)))
QuickSort arrWerte
ComboBox1.List = arrWerte
End Sub
Sub QuickSort(ByRef VA_Array, Optional V_Low1, Optional V_High1)
' https://www.herber.de/forum/ _
archiv/108to112/t109556.htm
On Error Resume Next
Dim V_Low2 As Long, V_High2 As Long
Dim V_Val1, V_Val2 As Variant
If IsMissing(V_Low1) Then
V_Low1 = LBound(VA_Array, 1)
End If
If IsMissing(V_High1) Then
V_High1 = UBound(VA_Array, 1)
End If
V_Low2 = V_Low1
V_High2 = V_High1
V_Val1 = VA_Array((V_Low1 + V_High1) / 2)
While (V_Low2  V_Val1 And _
V_High2 > V_Low1)
V_High2 = V_High2 - 1
Wend
If (V_Low2  V_Low1) Then Call _
QuickSort(VA_Array, V_Low1, V_High2)
If (V_Low2 



Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige