Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sorting texts and numbers as if it was all numbers


Hi,

I have a list of appartement numbers. Sometimes it's written 102 o
sometimes 102a and 102b.

E.G

102
103
104a
104b
105
(...)

Actually, if I record a macro to sort those valuesm it puts 104a an
104b at the end of the list, without considering them as numbers whic
are locally before 105. Note that it could be one, two, three or mor
digits. It would be a dynamic lenght. The letter too could be dynami
as well.

Is there a way to tell Excel/VBE to sort intelligently this list?

Thx!

Werner


Code
-------------------


Sub Sorting()

Rows("16:29").Select
Selection.Sort Key1:=Range("A16"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub


-------------------

--
Werne
-----------------------------------------------------------------------
Werner's Profile: http://www.excelforum.com/member.php...fo&userid=2430
View this thread: http://www.excelforum.com/showthread.php?threadid=38524

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Sorting texts and numbers as if it was all numbers

You need to create a new column (Call it sort) and make it the text values of
all of the numbers and text. Sort based on this new column and then delete
the column when you are done. Or just convert all of the numbers to text and
then sort.
--
HTH...

Jim Thomlinson


"Werner" wrote:


Hi,

I have a list of appartement numbers. Sometimes it's written 102 or
sometimes 102a and 102b.

E.G

102
103
104a
104b
105
(...)

Actually, if I record a macro to sort those valuesm it puts 104a and
104b at the end of the list, without considering them as numbers which
are locally before 105. Note that it could be one, two, three or more
digits. It would be a dynamic lenght. The letter too could be dynamic
as well.

Is there a way to tell Excel/VBE to sort intelligently this list?

Thx!

Werner


Code:
--------------------


Sub Sorting()

Rows("16:29").Select
Selection.Sort Key1:=Range("A16"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub


--------------------


--
Werner
------------------------------------------------------------------------
Werner's Profile: http://www.excelforum.com/member.php...o&userid=24304
View this thread: http://www.excelforum.com/showthread...hreadid=385246


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sorting texts and numbers as if it was all numbers


It's logic, it could work easily. But the, how could I convert th
numbers into text? Do you have a vba code for that

--
Werne
-----------------------------------------------------------------------
Werner's Profile: http://www.excelforum.com/member.php...fo&userid=2430
View this thread: http://www.excelforum.com/showthread.php?threadid=38524

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sorting texts and numbers as if it was all numbers


I converted the numbers in text but it didn't sort correctly the numbers
which have a string character at the end. Maybe my sorting formula in
VBA needs a bit more of precision?


Code:
--------------------

With Worksheets("Formulaire")
'The line used to convert numbers into text
Range("A16:A" & lstRw).NumberFormat = "@"
Rows("16:" & lstRw).Select
Selection.Sort Key1:=Range("A16"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=True, Orientation:=xlTopToBottom

Range("A15").Select
End With


--------------------


--
Werner
------------------------------------------------------------------------
Werner's Profile: http://www.excelforum.com/member.php...o&userid=24304
View this thread: http://www.excelforum.com/showthread...hreadid=385246

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sorting texts and numbers as if it was all numbers


I've done a search in another forum, ozgrid.com forum and I have found a
post going back to july 20th 2004. Derk, an excel expert, has posted
back then an amazing search macro that works like magic. It resolved
instanly all my problems in an efficient way. Here's the link :

http://www.ozgrid.com/forum/showthre...t+text+numbers

I say thanks to Derk for that code!

Werner


--
Werner
------------------------------------------------------------------------
Werner's Profile: http://www.excelforum.com/member.php...o&userid=24304
View this thread: http://www.excelforum.com/showthread...hreadid=385246



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Sorting texts and numbers as if it was all numbers

The question you posted there doesn't make much sense to me. The sample
data you show is already sorted on both columns from what I can tell.

--
Regards,
Tom Ogilvy


"Werner" wrote in
message ...

I've done a search in another forum, ozgrid.com forum and I have found a
post going back to july 20th 2004. Derk, an excel expert, has posted
back then an amazing search macro that works like magic. It resolved
instanly all my problems in an efficient way. Here's the link :


http://www.ozgrid.com/forum/showthre...t+text+numbers

I say thanks to Derk for that code!

Werner


--
Werner
------------------------------------------------------------------------
Werner's Profile:

http://www.excelforum.com/member.php...o&userid=24304
View this thread: http://www.excelforum.com/showthread...hreadid=385246



Reply
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
sorting numbers and numbers that contain text in excel MZ Excel Discussion (Misc queries) 3 November 25th 09 07:45 AM
Extract texts & numbers from one cell into four cells Ed Excel Discussion (Misc queries) 3 January 25th 08 04:57 AM
List of unique texts and numbers vsoler Excel Worksheet Functions 7 May 19th 07 06:47 PM
Conditional Formatting : Numbers & Texts Conflict nayinky Excel Worksheet Functions 3 August 8th 06 07:15 AM
convert numbers to texts sampath Excel Worksheet Functions 1 December 2nd 04 01:18 PM


All times are GMT +1. The time now is 07:23 AM.

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"