Option Explicit
Private Type Demand
State As String
Pack As String
Code As String
Value As Long
End Type
Sub sortThem()
Dim a() As Demand
ReDim a(1 To 3)
With a(1)
.Value = 4
.Code = "Item1"
End With
With a(2)
.Value = 0
.Code = "Item2"
End With
With a(3)
.Value = 1
.Code = "Item3"
End With
MsgBox a(1).Code & ", " & a(2).Code & ", " & a(3).Code
a = BubbleSortDemands(a)
MsgBox a(1).Code & ", " & a(2).Code & ", " & a(3).Code
End Sub
Public Function BubbleSortDemands(data() As Demand) As Demand()
Dim a As Long
Dim e As Integer, f As Integer, g As Integer
Dim i As Demand, j As Demand
Dim m() As String, n() As Demand
e = 1
n = data
Do While e <> -1
For a = LBound(data) To UBound(data) - 1
i = n(a)
j = n(a + 1)
If i.Value > j.Value Then
n(a) = j
n(a + 1) = i
g = 1
End If
Next a
If g = 1 Then
e = 1
Else
e = -1
End If
g = 0
Loop
BubbleSortDemands = n
End Function