View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
kounoike[_2_] kounoike[_2_] is offline
external usenet poster
 
Posts: 126
Default How to do this kind of sorting?

If you don't mind using helper columns, try this.

put in B1
=A1
then put B1
{=IF(MIN(ABS(B$1:B1-A2))=MIN(A$1:A$14),A2,A2+MAX(A$1:A$14))}
this is a array formula(Ctrl+Shift+enter), and copy B2 down to B14.

put C1
=IF(A1=B1,ROW(),"")
and copy C1 down to C14.

put D1
=IF(ISERROR(SMALL(C$1:C$14,ROW())),"",INDEX(A$1:A$ 14,SMALL(C$1:C$14,ROW())))
and copy D1 down to C14.

this will populate 13 8 3 23 19 in D1:D5

keizi

"Eric" wrote in message
...
Referring to Excel General Question
Does anyone know how to perform this kind of sorting in excel?

13, 8, 7, 7, 14, 14, 14, 3, 3, 3, 23, 19, 2, 2

The above values are listed from cell A1 to A14
A1 has a higher priority than A2 on selection, and A14 has the lowest
priority on selection, because it located on the bottom of the list. I
need
to select the top five numbers from the list without duplication, but the
distance between any two numbers must be bigger than / [equal to] the
smallest value from the list. On the other words, 2 is the smallest number
from the list,

13, 8, 7, 7, 14, 14, 14, 3, 3, 3, 23, 19, 2, 2
the first number is 13 for selection, and
[13]

13, 8, 7, 7, 14, 14, 14, 3, 3, 3, 23, 19, 2, 2
the second number is 8, which 13-8=5 and is bigger than / equal to the
smallest number 2.
[13 8]

13, 8, 7, 7, 14, 14, 14, 3, 3, 3, 23, 19, 2, 2
the third number cannot be 7, because abs(8-7)=1, which is less than the
smallest number 2, even through abs(13-7)=6, which is bigger than 2.
the next third number cannot be 7 again, then skip it for the next one.
the next third number cannot be 14, because abs(13-14)=1, which is less
than
2.
...
the next third number is 3, abs(13-3)=10, abs(8-3)=5, which is bigger than
2
[13 8 3]

13, 8, 7, 7, 14, 14, 14, 3, 3, 3, 23, 19, 2, 2
the next forth number is 23, which is OK, abs(13-23)=10, abs(8-23)=15,
which
is bigger than 2
[13 8 3 23]

13, 8, 7, 7, 14, 14, 14, 3, 3, 3, 23, 19, 2, 2
the next fifth number is 19, abs(13-19)=6, abs(8-19)=11, abs(23-19)=4,
abs(3-19)=16

[13 8 3 23 19] DONE, which values are stored in cell B1 to B5

Does any have any suggestion?
Thank you very much in advance
Eric