ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sorting problem (https://www.excelbanter.com/excel-programming/327408-sorting-problem.html)

broogle

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.


Toppers

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.



Toppers

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.




All times are GMT +1. The time now is 10:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com