Hi all, this problem has been giving me headaches all day. I have a string array called a(12) and one single with values called b(12). I want to sort the b(12) from low to high but at the same time sort the a(12) when needed to keep the matches (ex a(4) with b(4). I want to use the bubble sort routine as module.

This is what I have in mind which doesn't work
Code:
Sub bsort(a() As String, b() As Single)
Dim n As Integer
Dim i As Integer, j As Integer
For j = n To 1 Step -1
   For i = 1 To j - 1
      If b(i) > b(i + 1) Then
         Call swap(b(i), b(i + 1))
         Call swap(a(i), a(i + 1))
      End If
   Next
Next
End Sub
Instead if I use this one in command button of a user form it works
VB Code:
  1. Private Sub CommandButton3_Click()
  2. dim a(12) as string, b(12) as single
  3. Dim n As Integer, i As Integer
  4. n = UBound(a)
  5. For j = n To 1 Step -1
  6.    For i = 1 To j - 1
  7.       If b(i) > b(i + 1) Then
  8.          Call swap(b(i), b(i + 1))
  9.          Call swap(a(i), a(i + 1))
  10.       End If
  11.    Next
  12. Next
  13. For i = 1 To n
  14.     Cells(i, 8) = a(i)
  15.     Cells(i, 9) = b(i)
  16. Next i
  17. End Sub

I don't see any differences, why is that happening? Thanks in advance