Option Explicit
Option Base 1
Sub Sort_an_Array()
Dim strArray(12) As String
Dim strTemp As String
Dim X As Integer, Y As Integer, i As Integer
strArray(1) = "n"
strArray(2) = "d"
strArray(3) = "h"
strArray(4) = "g"
strArray(5) = "e"
strArray(6) = "d"
strArray(7) = "o"
strArray(8) = "p"
strArray(9) = "m"
strArray(10) = "h"
strArray(11) = "b"
strArray(12) = "m"
Debug.Print "Current items in array:"
For i = 1 To UBound(strArray)
Debug.Print strArray(i)
Next i
For X = LBound(strArray) To (UBound(strArray) - 1)
For Y = (X + 1) To UBound(strArray)
If strArray(X) > strArray(Y) Then
strTemp = strArray(X)
strArray(X) = strArray(Y)
strArray(Y) = strTemp
strTemp = ""
End If
Next Y
Next X
Debug.Print "Items in sorted array:"
For i = 1 To UBound(strArray)
Debug.Print strArray(i)
Next i
End Sub
|