How to sort strings from specific position?

lalaluye

New Member
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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
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)

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

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:

Replies
0
Views
153
Replies
8
Views
155
Replies
4
Views
428
Replies
2
Views
247
Replies
1
Views
180

Threads
1,203,069
Messages
6,053,352
Members
444,655
Latest member
didr

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

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