sort numeric array

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi! I have an array with numbers. i want to sort the array based on the size
of the numers. how can i do this? do I need to write a function for it or
does it exist in vba already? please help!
 
here's an example, don't remember who posted it, though:

Sub sort_array()
Dim arr As Variant
Dim i As Long, j As Long, temp As Long
'sort the array
arr = Array(2, 3, 4, 1, 6, 8, 7)
For i = LBound(arr) To UBound(arr) - 1
For j = i + 1 To UBound(arr)
If arr(i) > arr(j) Then
temp = arr(j)
arr(j) = arr(i)
arr(i) = temp
End If
Next j
Next i
MsgBox arr(0)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top