Forum Discussion
PatDor
Jan 28, 2025Copper Contributor
Sorting
How do I sort a text field by the first digits? I would like it to sort these as 0031 0031A 0033 0033A. Instead it is sorting as 0031 0033 0031A 0033A
m_tarler
Jan 28, 2025Bronze Contributor
Text will be sorted as you request. The way you don't want it to be sorted happens if 0031 and 0033 are entered as numbers (not forced to be text). As example see below:
column B has all entries as forced to be text and sorted as preferred but column C was not forced to be TEXT so 0031 and 0033 are numbers.
So during entry if you format that column as TEXT instead of GENERAL it will force those entries as TEXT. Alternatively you can enter the values prefixed with an apostrophy (') so '0031 will be treated and shown as text of 0031.
Lastly in column D I did use a formula to force each to be text and then sort it.
EDIT: just realize the TEXT formula allows arrays fine so no BYROW needed:
=SORT(TEXT(C1:C4,"0000"))