Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting based on qty - through formulea 1

Status
Not open for further replies.

iken

Mechanical
May 13, 2003
151
0
0
NZ
Hi,

Just wondering if anyone knew of a way to sort a bunch of numbers, based on a formulea (macro is easy, but would like a formulea.

What I am trying to do is sort some numbers based on a frequency they show up.

i.e
Numbers 1 2 3 4 5 etc
Freq 4 5 1 1 0 etc

I also need to take into account differeing numbers that have the same freq as others.

So my result would be (from most freq to least)
Result 2 1 3 4 5

Thanks,

 
Replies continue below

Recommended for you

?? That's all done in the sort dialog; you sort on frequency first, then the ordinality.

TTFN
faq731-376
7ofakss
 
I did something like this quite a while ago with help from this forum...I recall it involved the RANK function.

Try doing a search using keywords "Sort by formula" or "Sort by function"
 
You can use the mode function to get the one with the highest frequency and then delete or add a code to remove them and repeat again and again.
 
But, I don't think there is a formulaic way for Excel to move data around. That can only be done by VBA; pivot tables are a possibility, but they're mostly run by dialogs, just like Sort.

TTFN
faq731-376
7ofakss
 
AELLC, I tried your sheets, but when I changed the freq, all cells went #name

I have used the sort function with a macro. Not ideal but will do.

Thanks all
 
OK, I was only looking at a series of numbers that start at 1 and increment by 1 as stated in your OP

i.e. 1 2 3 4 5 6 etc

For anything else such as 5 8 3 1 12 26 4 etc
there would have to be another step using the OFFSET function to return the actual number in the sorted column of results.
 
iken - What version of Excel are you using? If prior to 2010 replace the Rank.eq function with Rank and it will give the results as shown. But I don't think this is the result you want. With the numbers shown it gives the correct results, but that's coincidental. If you play with the frequencies you will find that in general it doesn't give the right order.

You could use the Match function to find the position of each rank, then use the index (or offset) function to return the actual value for that rank, if they were not in sequential order. This still has a problem if there are two of equal rank though, as the second match on that rank will return #NA. At the moment I can't see a simple way around that.

The sort function I linked to previously seems like the simplest solution to me. Are you wanting to avoid VBA altogether, or just trying to avoid a macro that will need to be initiated to give the correct results?

A spreadsheet is attached with examples of the Rank/Match method and the UDF sort function.

Doug Jenkins
Interactive Design Services
 
Thanks IDS,

I were trying to avaid VBA and macro's solely for ease (and the fact I and otehrs would need to enable the macro at the start.

I have given into this though, and have a macro that sorts the data with a click on an "update data" button.

Thanks All
 
Status
Not open for further replies.
Back
Top