ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Do we have time for yet another Sort problem? (https://www.excelbanter.com/excel-programming/393482-do-we-have-time-yet-another-sort-problem.html)

theSquirrel

Do we have time for yet another Sort problem?
 
I have a worksheet with various bits of data (mostly numeric values)
but with some text type characters sparingly used. Below is an
example of the data I am working with:

0
1+x
1
5
1
1
1
2
4
1
3
3(1)
0
0
0
0

Now... if i sort it i end up getting this.
0
0
0
0
0
1
1
1
1
1
2
3
4
5
1+x
3(1)

You will notice that I have 2 values at the bottom that I would like
to see next to their corresponding number instead of sorted as text at
the bottom.

So far I have tried to format the cells containing the values as TEXT,
I have tried to use the DataOption1:=xlSortTextAsNumbers

Here is the code I am using to sort with:

Public Sub SortMain(SortColumnAndRow As String)
Set SortKey = TempList.Range(SortColumnAndRow)

SortRange.Sort Key1:=SortKey, _
Order1:=xlAscending, _
Header:=xlNo, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

Anyone have any ideas on what I can do?


excelent

Do we have time for yet another Sort problem?
 
If u have data in A1:A16, and B1:B16 is free
Sub xSort()
For t = 1 To 16
Cells(t, 2) = Val(Cells(t, 1))
Next
Range("A1:B16").Select
Selection.Sort Key1:=Range("B1"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("B1:B16").Select
Selection.ClearContents
Range("B1").Select
End Sub



"theSquirrel" skrev:

I have a worksheet with various bits of data (mostly numeric values)
but with some text type characters sparingly used. Below is an
example of the data I am working with:

0
1+x
1
5
1
1
1
2
4
1
3
3(1)
0
0
0
0

Now... if i sort it i end up getting this.
0
0
0
0
0
1
1
1
1
1
2
3
4
5
1+x
3(1)

You will notice that I have 2 values at the bottom that I would like
to see next to their corresponding number instead of sorted as text at
the bottom.

So far I have tried to format the cells containing the values as TEXT,
I have tried to use the DataOption1:=xlSortTextAsNumbers

Here is the code I am using to sort with:

Public Sub SortMain(SortColumnAndRow As String)
Set SortKey = TempList.Range(SortColumnAndRow)

SortRange.Sort Key1:=SortKey, _
Order1:=xlAscending, _
Header:=xlNo, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

Anyone have any ideas on what I can do?




All times are GMT +1. The time now is 05:11 AM.

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