Tricky Sort solution sought

mikemcbain

Board Regular
Joined
Nov 14, 2005
Messages
152
Office Version
  1. 365
Platform
  1. Windows
G'day Magicians

Everyday I have extensive columns of info like the below...

I need to Sort it on the Form column so that the first rows contain the blank cells, followed by rows which contain any cells finishing with an x, followed by rows with cells finishing in x and one number, then x and two numbers, and then x and three numbers and finally four numbers.
Any suggestions gratefully considered.

Mike
Tasmania
Code:
RNO	 TNO	 RDST   FORM
7	13	1100	  16x
2	12	1100	  2x0
2	11	1100	  4x29
5	3	1400	  37x3
3	1	1100	  x223
2	8	1100	
3	7	1100	  0x34
2	5	1100	  1x
8	3	1100	  376x
3	9	1100	  16x
4	7	1400	  14x4
3	6	1100	  241x
2	14	1100	
1	5	1400	  0x68
7	3	1100	  1381
 
Last edited:

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
you can add a helper column, then sort by that column


D2 FORMULA IS: =IF(C2="",0,LEN(C2)-SEARCH("x",C2)+1) and drag down


Excel 2010
ABCDEFGHIJK
1RNOTNORDSTFORMsrt colRNOTNORDSTFORMsrt col
27 13110016x12 80
32 1211002x022 140
42 1111004x2937 13110016x1
55 3140037x322 511001x1
63 111001x22348 31100376x1
72 803 9110016x1
83 7110080x3433 61100241x1
92 511001x12 1211002x02
108 31100376x15 3140037x32
113 9110016x14 71400714x42
124 71400714x422 1111004x293
133 61100241x13 7110080x343
142 1401 5140000x683
151 5140000x6833 111001x2234
167 3110055x34568777 3110055x3456877
Sheet4
 
Upvote 0
If you're happy using a helper column, paste the below into a spare column and then sort on that column...
=IFERROR(IF(LEN(D2)=0,1,IF(RIGHT(D2)="x",2,2+LEN(D2)-FIND("x",D2))),6)
 
Upvote 0
Hi Mike,

Would you be open to adding an extra column with a formula to something similar below

=IFERROR(LEN(D2)-(FIND("x",D2)),-1)?

You could sort this column from smallest to largest.
 
Upvote 0
wesleyferns, njimack & VBA Geek

Perfect and thank you all very much!

I will trial each of your suggestions and expect them all to work perfectly for my purpose.

You really are magicians.

Mike
Tasmania.
 
Upvote 0
VBA GEEK

I have chosen to go with your solution however unfortunately I missed one example that we must cater for in my original post and that is the occasional cell with no x but just a single number like shown below.
Code:
RNO	TNO	RDSTFORM	srt col
7 13	1100	16x	1
2 12	1100	2x0	2
2 11	1100	4x29	3
5 3	1400	37x3	2
3 1	1100	1x223	4
2 8			0
3 7	1100	80x34	3
2 5	1100	4	[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=VALUE]#VALUE[/URL] !
8 3	1100	376x	1
3 9	1100	16x	1
4 7	1400	714x4	2
3 6	1100	241x	1
2 14			0
1 5	1400	00x68	3
7 3	1100	55x345687	7

I have tried to find a solution but am sure you can come up with something simple?

With thanks

Mike.
Tasmania
 
Last edited:
Upvote 0
How should this be ranked?

VBA GEEK

I have chosen to go with your solution however unfortunately I missed one example that we must cater for in my original post and that is the occasional cell with no x but just a single number like shown below.
Code:
RNO    TNO    RDSTFORM    srt col
7 13    1100    16x    1
2 12    1100    2x0    2
2 11    1100    4x29    3
5 3    1400    37x3    2
3 1    1100    1x223    4
2 8            0
3 7    1100    80x34    3
2 5    1100    4    [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=VALUE"]#VALUE[/URL] !
8 3    1100    376x    1
3 9    1100    16x    1
4 7    1400    714x4    2
3 6    1100    241x    1
2 14            0
1 5    1400    00x68    3
7 3    1100    55x345687    7

I have tried to find a solution but am sure you can come up with something simple?

With thanks

Mike.
Tasmania
 
Upvote 0
I would prefer this to be ranked immediately after the Blank cell and before the x? cell but for simplicity the same ranking as x? would be fine.
 
Upvote 0
I would prefer this to be ranked immediately after the Blank cell and before the x? cell but for simplicity the same ranking as x? would be fine.


you can update the formula in D2 to
Code:
=IF(C2="",0,IF(ISERROR(SEARCH("x",C2)),1,LEN(C2)-IFERROR(SEARCH("x",C2),LEN(C2))+2))
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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