confused sort range based on names in column

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hi experts
I try sorting data based on column B
this is what I want
a.xlsx
ABCDEFG
71alla127422/05/20061549
82alla226601/07/20061530
93alla327520/08/200615111
104alla427608/02/200714723
115alla527120/01/200714811
126alla626613/05/200615418
137alla727118/06/200615313
148alla826929/09/20051602
159alla927602/07/200615229
1610alla1026901/07/20061530
ss
Cell Formulas
RangeFormula
E7:E16E7=IF($D7="","",DATEDIF($D7,DATE(YEAR(NOW()),10,1),"y"))
F7:F16F7=IF($D7="","",DATEDIF($D7,DATE(YEAR(NOW()),10,1),"ym"))
G7:G16G7=IF($D7="","",DATEDIF($D7,DATE(YEAR(NOW()),10,1),"md"))

but suddenly this is what I got

a.xlsx
ABCDEFG
71alla127422/05/20061549
82alla1026901/07/20061530
93alla1127524/07/20061527
104alla1227601/06/20061540
115alla1327125/09/20051606
126alla1427201/08/20061520
137alla1526928/09/20061503
148alla1627002/05/200615429
159alla1727127/04/20061554
1610alla1827114/01/200615817
1711alla226601/07/20061530
1812alla327520/08/200615111
1913alla427608/02/200714723
2014alla527120/01/200714811
2115alla626613/05/200615418
2216alla727118/06/200615313
ss
Cell Formulas
RangeFormula
E7:E22E7=IF($D7="","",DATEDIF($D7,DATE(YEAR(NOW()),10,1),"y"))
F7:F22F7=IF($D7="","",DATEDIF($D7,DATE(YEAR(NOW()),10,1),"ym"))
G7:G22G7=IF($D7="","",DATEDIF($D7,DATE(YEAR(NOW()),10,1),"md"))

how should fix,please?
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
That is correct alphabertic sorting. Remember, you are sorting alphanumeric values, not numeric ones!
In alphanumeric sorting, it looks at each character individually, so "1" always come before "2", so values like "10", "11", "12", will come before "2".

There are various ways to get the data to sort the way that you want. Here are a few options:

1. Split up your values into two columns, so the "alpha" part is in one column, and the "numeric" part is in another column (as a number and not text), and sort by both these columns.

2. Change the format of your values so that there are always two spaces for the numbers, so values like "alla1" would be re-written as "alla01". Then things would sort the way you want.

3. If your entries all follow the same structure (4 character alpha prefix plus number), use a "helper" column to sort, using a formula that creates entries like mentioned in option two above.
That formula would look something like:
Excel Formula:
=IF(LEN(B7=5),LEFT(B7,4) & "0" & RIGHT(B7,1),B7)
 
Upvote 0
thanks for the suggestions . about OPTION3 it's differnt . not the same structure
actually I wish if can do that as in picture1
 
Upvote 0
actually I wish if can do that as in picture1
I know what you want to do, and I told you why it is not working. Do you understand the issue?
Sorting text or alphanumeric values is NOT the same as sorting totally numeric values.

Have you considered either of the other two options?
 
Upvote 0
do you try to say me my way is not possible without use your suggestion?
 
Upvote 0
do you try to say me my way is not possible without use your suggestion?
Not necessarily use my suggestion. There may be other ways of doing (perhaps by creating some Custom sort rule).
But you cannot get it to do what you want using the default sort functionality.
You are going to do something on your end, whether it is change the data, use helper columns, create Custom sorting rules, or use VBA.
 
Upvote 0
use helper columns,
I don't prfer this choice . I don't want adding more data in my sheet . I prefer doing directly
create Custom sorting rules, or use VBA.
good choices. may be another body can help if you can't do that .
 
Upvote 0
How about updating your data to add in the missing 0?
We could probably come up with VBA code to automatically add that in there. Then you could sort normally.
Is that a possibility?
If it is, could you post a sampling of your "real" data, so we can see exactly what it looks like, and make sure that the code we create will work on it?
Be sure to include different formats/possibilities that you have.
 
Upvote 0
I have been looking into this more, and I do not thing that a Custom sort would work for you. In a Custom sort, you must provide a complete list of all possible values, and the order you want them sorted in. That is really intended for situations in which you have a limited, defined number of options, such as a drop-down list selection like:
- High
- Medium
- Low

and you want them sorted in that particular order.

I am guessing that you will not be able to pre-define all the possible values you may have, especially if the values contain "counters" on the end (the is no limit to the numbers).

In searching other similar question around the internet, almost all the solutions involved using "helper" columns.

So I think you really just have two options here:
1. Enlist the use of helper columns for sorting purposes (which you can hide, by the way).
2. Fix/update the data, as I described in my previous post.

Note that you can use VBA in conjunction with either of these solutions. You could even have VBA add the helper columns, complete the sort, then delete the helper columns after the sort if finished.
The choice is yours.
 
Last edited:
Upvote 0
A.xlsm
ABCDEFG
5itemnamesumdateold
6yearmonthday
71ALI132667/1/20061530
82ALI142728/1/20061520
93ALI152699/28/20061503
104ALI162705/2/200615429
115ALI12745/22/20061549
126ALI22714/27/20061554
137ALI32675/9/200615422
148ALI42714/8/200615523
159ALI52692/24/20071477
1610ALI62691/10/200714821
1711ALI72751/12/200714819
1812MAHMOUD52758/20/200615111
1913MAHMOUD62661/4/200714827
2014MAHMOUD72712/15/200714716
2115MAHMOUD12691/7/200714824
2216MAHMOUD22679/3/200615028
2317MAHMOUD32762/8/200714723
2418MAHMOUD42711/20/200714811
2519KALID42665/13/200615418
2620KALID52716/18/200615313
2721KALID62699/29/20051602
2822KALID12767/2/200615229
2923KALID22728/1/20061520
3024KALID326910/6/2006141125
SS
Cell Formulas
RangeFormula
E7:E30E7=IF($D7="","",DATEDIF($D7,DATE(YEAR(NOW()),10,1),"y"))
F7:F30F7=IF($D7="","",DATEDIF($D7,DATE(YEAR(NOW()),10,1),"ym"))
G7:G30G7=IF($D7="","",DATEDIF($D7,DATE(YEAR(NOW()),10,1),"md"))

RESULT should be
1طباعة.xlsm
ABCDEFG
5itemnamesumdateold
6yearmonthday
71ALI12745/22/20061549
82ALI22714/27/20061554
93ALI32675/9/200615422
104ALI42714/8/200615523
115ALI52692/24/20071477
126ALI62691/10/200714821
137ALI72751/12/200714819
148ALI132667/1/20061530
159ALI142728/1/20061520
1610ALI152699/28/20061503
1711ALI162705/2/200615429
1812KALID12767/2/200615229
1913KALID22728/1/20061520
2014KALID326910/6/2006141125
2115KALID42665/13/200615418
2216KALID52716/18/200615313
2317KALID62699/29/20051602
2418MAHMOUD12691/7/200714824
2519MAHMOUD22679/3/200615028
2620MAHMOUD32762/8/200714723
2721MAHMOUD42711/20/200714811
2822MAHMOUD52758/20/200615111
2923MAHMOUD62661/4/200714827
3024MAHMOUD72712/15/200714716
SS
Cell Formulas
RangeFormula
E7:E30E7=IF($D7="","",DATEDIF($D7,DATE(YEAR(NOW()),10,1),"y"))
F7:F30F7=IF($D7="","",DATEDIF($D7,DATE(YEAR(NOW()),10,1),"ym"))
G7:G30G7=IF($D7="","",DATEDIF($D7,DATE(YEAR(NOW()),10,1),"md"))



about a drop-down list selection should be M2
 
Upvote 0

Forum statistics

Threads
1,215,516
Messages
6,125,285
Members
449,218
Latest member
Excel Master

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