PDA

View Full Version : top five items



Yvaine
07-14-2008, 09:12 PM
Given a 2-dimension array like below
arry(0,0) = A
arry(0,1) = 11
arry(1,0) = "B"
arry(1,1) = "1"
....

Lazy to assign one by one..The layout is like this
A 11
B 1
C 3
D 5
E 43
G 1
H 1
I 0

In fact we do not know what are the items in the array, what i hv put is just example.
Ok, the task is to get top 5 items. In this case the result should be
E 43
A 11
D 5
C 3
B 1
G 1
H 1

If the top 5 6 7 ..... is having the same number, all of them should be included in the result.

Anyone can tell me how to code it?

OBP
07-15-2008, 01:50 AM
Assuming that the data always has the preceding Single Letter you do not need VBA Code to do this. A query will do it.
If you are just doing it for a "Learning Exercise" then you would need to to use a Sort routine like a "Bubble Sort" and then display the top items checking for duplication of the 5th item.