LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Ron Rosenfeld
 
Posts: n/a
Default

On Thu, 13 Oct 2005 12:07:36 -0500, Gerard
wrote:


ladies and gentlemen i have a challenge for you all. i wish to sort
cattle details using excel. i download the details from the department
of agriculture as follows;
UK 9 12345 678 6
UK 9 12345 679 7
UK 9 12345 680 1
UK 9 12345 681 2
where the "UK 9" is constant,
the "12345" is the herd number of animals-which i do not wish to sort,
the "678" is the individual animal's number, which i wish the animals
to be sorted in order of,
and the "1"-"7" is a "check number", every animal has the random number
1-7 at the end of their number.
As you can see, there are spaces between each different bit of
information.

you may think that this is easy, but what makes it more complicated
is;
the herd number, (e.g. 12345) is not necessarily 5 digits long, it can
range from about 4 to 8 digits, also in my herd of cattle there is a
wide variety of herd numbers, therefore not all 5 digits herd numbers
are the same.

to make matters more complicated, there are also animals in my herd
which are in a slightly different format;
314159-180-N
314159-181-O
314159-182-P
314159-183-Q
where there is no "UK 9"
the "314159" is the herd number of animals-which i do not wish to
sort,
the "180" is the individual animals number, which i wish the animals to
be sorted in order of,
and the "A-Z" is a "check letter", every animals has the random letter
"A-Z" at the end of their number.
As you can see, there are "-" between each different bit of
information.

if you would be able to tell me how to sort the animals numbers i would
greatly appriciate it.
if i cannot arrange both formats of data in order of animals number at
the same time, but can arrange each format of data in order of animals
number individually, i would still greatly appriciate it!

Thanks a million
Gerard


I'm just learning about "regular expressions" and they seem ideal for this. Of
course, you have to install Longre's free morefunc.xll add-in (available at
http://xcell05.free.fr/).

The following formula will extract the second to last "word" of your data,
whether separated by <space or "-" 's.

=REGEX.MID(A1,"[^[:punct:]\s]+",-2)

Given your examples, it returns:

314159-180-N
314159-181-O
314159-182-P
314159-183-Q
UK 9 12345 678 6
UK 9 12345 679 7
UK 9 12345 680 1
UK 9 12345 681 2

To extract the second to last word using built-in Excel functions is certainly
possible, but it's a bit less flexible.

If your animal numbers are always three digits, and the check number or letter
follows and is only one character, then the simple:

=MID(A1,LEN(A1)-4,3)

will work. But more complex situations may be more difficult, depending on
your ranges.

In either of the above, you then sort on your "helper column".


--ron
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select rows and sort based on type Sarah Excel Discussion (Misc queries) 0 October 11th 05 05:06 PM
Conform a total to a list of results? xmaveric Excel Discussion (Misc queries) 1 August 21st 05 07:22 PM
Conform a total to a list of results? xmaveric Excel Worksheet Functions 0 August 21st 05 10:42 AM
sorting more than 3 keys Brooke Excel Discussion (Misc queries) 3 June 18th 05 04:52 AM
"-" ignored in sort Mike H Excel Discussion (Misc queries) 8 January 2nd 05 07:48 AM


All times are GMT +1. The time now is 04:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"