Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Sorting problem

Any body knows how to sort:

A2,A1,A3,A21,A31,A25 to be A1,A2,A3,A21,A25,A31 ??
Currently the result I got was A1,A2,A21,A25,A3,A31.

Thanks a million.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Sorting problem

You can only achieve your result by making A1, A2, A3 = A01,A02,A03.

"broogle" wrote:

Any body knows how to sort:

A2,A1,A3,A21,A31,A25 to be A1,A2,A3,A21,A25,A31 ??
Currently the result I got was A1,A2,A21,A25,A3,A31.

Thanks a million.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Sorting problem

You could try this which adds a column, adds leading 0 (zero) to the data
and places in the added column, sorts it and deletes column. It assumes
original data to be sorted is in column A and that digits lie between 1 and
99 i.e A1 to A99.

Sub Sort()

Columns(1).Insert

ilastrow = Cells(Rows.Count, "B").End(xlUp).Row ' Was originally A
For i = 2 To ilastrow
Cells(i, "A") = Left(Cells(i, "B"), 1) & Format(Right(Cells(i, "B"),
Len(Cells(i, "B")) - 1), "00") ' Add leading zero
Next i

Range("A2:Z" & ilastrow).Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Columns(1).Delete

End Sub

HTH

"Toppers" wrote:

You can only achieve your result by making A1, A2, A3 = A01,A02,A03.

"broogle" wrote:

Any body knows how to sort:

A2,A1,A3,A21,A31,A25 to be A1,A2,A3,A21,A25,A31 ??
Currently the result I got was A1,A2,A21,A25,A3,A31.

Thanks a million.


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 problem Jack Sons Excel Discussion (Misc queries) 3 June 19th 08 11:07 PM
Sorting problem, need some help Chris B Excel Worksheet Functions 4 December 13th 06 06:26 PM
SORTING PROBLEM Grace Excel Worksheet Functions 2 September 27th 06 08:10 PM
Sorting problem Francine Excel Discussion (Misc queries) 2 July 7th 06 05:26 PM
Sorting problem Kal321 Excel Discussion (Misc queries) 2 January 27th 06 01:27 PM


All times are GMT +1. The time now is 09:49 PM.

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

About Us

"It's about Microsoft Excel"