How to sort strings from specific position?

lalaluye

New Member
Joined
May 20, 2015
Messages
14
For example I have several text strings

text_string_126778
text_string_123456
text_string_234567

I want to sort from position 15 to position 16

Result would be
text_string_123456
text_string_234567
text_string_126778

So other than position 15 and 16, the rest I dont care

xxxxxxxxxxxxx45x
xxxxxxxxxxxxx56x
xxxxxxxxxxxxx77x
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Just use the mid function and then sort from the helper column:

EXAMPLE:


Excel 2012
AB
1text_string_12345645
2text_string_23456756
3text_string_12677877
4text_string_12677977
Sheet3
Cell Formulas
RangeFormula
B1=MID(A1,16,2)
B2=MID(A2,16,2)
B3=MID(A3,16,2)
B4=MID(A4,16,2)
 
Upvote 0
Do you know of a way to write this in VBA?

If I do

Variable = Mid(A1, 16, 2)
Can Variable be assigned as an integer? Because I want to compare two variables (Numbers extracted from string) and see which one is smaller
 
Upvote 0
For example I have several text strings

text_string_126778
text_string_123456
text_string_234567

I want to sort from position 15 to position 16

Result would be
text_string_123456
text_string_234567
text_string_126778

So other than position 15 and 16, the rest I dont care

xxxxxxxxxxxxx45x
xxxxxxxxxxxxx56x
xxxxxxxxxxxxx77x
Is the "text_string_" part of your examples always going to be same length as shown so that the numbers you want to sort by will always be in position 15 and 16 for every cell value? If not, is the number part of your cell values always 6 digits long and you want to start at the 4th digit from the end?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,360
Messages
6,124,491
Members
449,166
Latest member
hokjock

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