Sub VariableSortieren()
Dim arrWert()
Dim strWert As String
Dim intZaehler As Integer
strWert = "erad"
' Größe des Array aus der Buchstabenanzahl festlegen, Array beginnt bei 0
ReDim arrWert(0 To Len(strWert) - 1)
' Schleife über alle Bestandteile der Variablen
For intZaehler = 1 To Len(strWert)
' jeweils Einzelwert ins Array eintragen
arrWert(intZaehler - 1) = Mid(strWert, intZaehler, 1)
Next intZaehler
' Array sortieren
QuickSort arrWert
' ursprünglichen Variableninhalt löschen
strWert = ""
' Schleife über alle Arrayfelder
For intZaehler = 0 To UBound(arrWert())
' Variable zusammensetzen
strWert = strWert & arrWert(intZaehler)
Next intZaehler
MsgBox strWert
End Sub
Sub QuickSort(ByRef VA_Array, Optional V_Low1, Optional V_High1)
'
http://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_High2)
While (VA_Array(V_Low2) < V_Val1 And _
V_Low2 < V_High1)
V_Low2 = V_Low2 + 1
Wend
While (VA_Array(V_High2) > V_Val1 And _
V_High2 > V_Low1)
V_High2 = V_High2 - 1
Wend
If (V_Low2 <= V_High2) Then
V_Val2 = VA_Array(V_Low2)
VA_Array(V_Low2) = VA_Array(V_High2)
VA_Array(V_High2) = V_Val2
V_Low2 = V_Low2 + 1
V_High2 = V_High2 - 1
End If
Wend
If (V_High2 > V_Low1) Then Call _
QuickSort(VA_Array, V_Low1, V_High2)
If (V_Low2 < V_High1) Then Call _
QuickSort(VA_Array, V_Low2, V_High1)
End Sub