trouble with sort

orsm6

Well-known Member
Joined
Oct 3, 2012
Messages
515
Office Version
  1. 365
Platform
  1. Windows
Hi all - I am trying to sort 2 columns of source data but it doesn't sort it as i need it to.

I am trying to build a sporting results 'ladder' and my sort formula is almost there, but not quite.
it will sort the first number correctly.

but if the first number is 0 then the sorted numbers are wrong, hopefully the screenshot will help.

how can I change my sort formula to also include the numbers after the '-'?: =SORT(AF4:AG44,2,-1)
 

Attachments

  • Screenshot 2023-10-18 080323.jpg
    Screenshot 2023-10-18 080323.jpg
    49.3 KB · Views: 28

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
One funky way is to replace the hyphen with nothing so 2-32 becomes 232 and 0-7 becomes 07, so that they can be effectively numbers and the sort should work

Excel Formula:
=SORTBY(AF4:AG44,SUBSTITUTE(AG4:AG44,"-","")*1,-1)
 
Upvote 0
One funky way is to replace the hyphen with nothing so 2-32 becomes 232 and 0-7 becomes 07, so that they can be effectively numbers and the sort should work

Excel Formula:
=SORTBY(AF4:AG44,SUBSTITUTE(AG4:AG44,"-","")*1,-1)
Hi Momentman, thanks for your help. OK i thought this didn't work... but i have a space before and after hyphen.

A new issue has come up... the range of source list has blanks, so the sorted list returns all the blanks as a bunch of zeros, how can they be excluded from the sorted list? see snip of result
 

Attachments

  • Screenshot 2023-10-18 113909.jpg
    Screenshot 2023-10-18 113909.jpg
    37.9 KB · Views: 17
Last edited:
Upvote 0
Try ..

23 10 18.xlsm
AFAGAHAIAJ
4a2 - 32d2 - 99
5g0 - 14a2 - 32
6b1 - 5x1 - 15
7d2 - 99b1 - 5
8x1 - 15g0 - 14
9
orsm6
Cell Formulas
RangeFormula
AI4:AJ8AI4=LET(f,FILTER(AF4:AG44,AG4:AG44<>""),SORTBY(f,SUBSTITUTE(TAKE(f,,-1)," - ","")*1,-1))
Dynamic array formulas.
 
Upvote 1
One funky way is to replace the hyphen with nothing so 2-32 becomes 232 and 0-7 becomes 07, so that they can be effectively numbers and the sort should work

Excel Formula:
=SORTBY(AF4:AG44,SUBSTITUTE(AG4:AG44,"-","")*1,-1)

Try ..

23 10 18.xlsm
AFAGAHAIAJ
4a2 - 32d2 - 99
5g0 - 14a2 - 32
6b1 - 5x1 - 15
7d2 - 99b1 - 5
8x1 - 15g0 - 14
9
orsm6
Cell Formulas
RangeFormula
AI4:AJ8AI4=LET(f,FILTER(AF4:AG44,AG4:AG44<>""),SORTBY(f,SUBSTITUTE(TAKE(f,,-1)," - ","")*1,-1))
Dynamic array formulas.
thanks again Peter - the skills of you guys is impressive. this got me out of a bind.


:)
 
Upvote 0
You're welcome again. :biggrin:
Hi Peter - sorry if this is incorrect to do, but something weird is going on with my ladder results. It doesn't seem to prioritise the first number then the number after the hyphen, you can see from my snip that the result 6 - 115 is in 3rd place but should be in 6th....

the result is from the formula that you supported me with in the above thread

are you able to help?
 

Attachments

  • ladder.png
    ladder.png
    3.3 KB · Views: 27
Upvote 0
It doesn't seem to prioritise the first number then the number after the hyphen,
I don't believe that we had that specific requirement stated previously so I guess not too surprising that it wasn't implemented. 😎

Also, are we still trying to sort two columns?
See if this sort of structure helps.

23 11 07.xlsm
ABCDE
1
2a8 - 410c8 - 503
3b4 - 23a8 - 410
4c8 - 503g8 - 89
5d6 - 60e6 - 115
6e6 - 115d6 - 60
7f0 - 60b4 - 23
8g8 - 89f0 - 60
9
10
Sort
Cell Formulas
RangeFormula
D2:E8D2=LET(f,FILTER(A2:B10,B2:B10<>""),r,TAKE(f,,-1),SORTBY(f,10^6*TEXTBEFORE(r,"-")+TEXTAFTER(r,"-"),-1))
Dynamic array formulas.
 
Upvote 0
Solution
I don't believe that we had that specific requirement stated previously so I guess not too surprising that it wasn't implemented. 😎

Also, are we still trying to sort two columns?
See if this sort of structure helps.

23 11 07.xlsm
ABCDE
1
2a8 - 410c8 - 503
3b4 - 23a8 - 410
4c8 - 503g8 - 89
5d6 - 60e6 - 115
6e6 - 115d6 - 60
7f0 - 60b4 - 23
8g8 - 89f0 - 60
9
10
Sort
Cell Formulas
RangeFormula
D2:E8D2=LET(f,FILTER(A2:B10,B2:B10<>""),r,TAKE(f,,-1),SORTBY(f,10^6*TEXTBEFORE(r,"-")+TEXTAFTER(r,"-"),-1))
Dynamic array formulas.
Hi Peter - apologies the initial request wasn't clear. Will keep that in mind for the future :)

but as it stands, this works great.

thanks again again :D
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,881
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top