View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Autosort on an Array

email me your file. There should be no reason why you need this crazy code.
this is a simple sort algorithm.




" wrote:

On Apr 20, 8:56 am, wrote:
Oh god, I've been a bit dim. I banged out that post quickly and meant
to say I want it to sort ascendingly by distance!!

I've tried manipulating the code, but have it sorting descendingly
(barring the first and last entires strangely) by distance.... so kind
of almost there...


Done it. Quite a lengthy way of doing it, don't know if it can be done
better. Managed to place the misplaced entry at the beginning of the
array at the end. Then that left a blank line for some reason, so did
a further loop through to cut off the opening line. Can't quite
visualise how the array was populating and why, so it ended up as a
bit of a tinker fest. Got there in the end though:

For x = 0 To (Count - 1)


For y = 1 To (Count)


If MyArray(x, 7) < MyArray(y, 7) Then


For z = 1 To 8


Temp = MyArray(x, z)
MyArray(x, z) = MyArray(y, z)
MyArray(y, z) = Temp


Next z


End If
Next y
Next x

MyArray2 = MyArray

For x = 1 To (Count)
y = 0
For z = 0 To 8
Temp = MyArray(x, z)
MyArray(y, z) = Temp
Next z
y = y + 1

Next x

For z = 0 To 8
Temp = MyArray2(0, z)
MyArray(Count, z) = Temp
Next z

y = 0

For x = 1 To (Count - 2)
For z = 0 To 8
Temp = MyArray(x, z)
MyArray(y, z) = Temp
Next z
y = y + 1
Next x


ListBox1.List = MyArray

LetsEnd: