Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
KAT KAT is offline
external usenet poster
 
Posts: 1
Default SORTING IN EXCEL 2003

In hopes that someone can help me:

I am trying to sort in a column the following in "numerical" order:

A2N1, A2N5, A2N10 (In this order)

It keeps sorting as follows: A2N1, A2N10, A2N5

Is there a way to fix this?

many thanks!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,316
Default SORTING IN EXCEL 2003

The following UDF will extract just the numeric values from your data and
then you can sort the numeric column. Press Alt+F11 to open the VBE, click
Insert on the menu and select MOdule. Paste the following in the blank
module:

Function ExtractNumbers(varVal As Variant) As Long

Dim intLen As Integer
Dim strVal As String
Dim i As Integer
Dim strChar As String

intLen = Len(varVal)

For i = 1 To intLen
strChar = Mid$(varVal, i, 1)
If IsNumeric(strChar) Then strVal = strVal & strChar
Next i

If Len(strVal) = 0 Then
ExtractNumbers = 0
Else
ExtractNumbers = CLng(strVal)
End If

End Function

Insert a blank helper column to the right of the column you wish to sort and
enter the custom formula:

=ExtractNumbers(CellAddress)

Where CellAddress is the first cell containing data. Copy the formula down
the columns and then do a Data/Sort using the helper column. Delete the
helper column following the sort
--
Kevin Backmann


"KAT" wrote:

In hopes that someone can help me:

I am trying to sort in a column the following in "numerical" order:

A2N1, A2N5, A2N10 (In this order)

It keeps sorting as follows: A2N1, A2N10, A2N5

Is there a way to fix this?

many thanks!

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,572
Default SORTING IN EXCEL 2003

Really, nothing is broken.
XL is sorting your data as Text, not as numbers.

If your data is exactly like your example, you can extract the ending
numbers into an adjoining, "helper" column, convert them to XL recognized
numbers, and then sort both columns together, using the "helper" column as
the sort key, and then finally delete that helper column.

With data in Column A, starting in A1, enter this formula into B1:

=--RIGHT(A1,LEN(A1)-3)

Copy down as needed, then sort *both* columns, using B as the key.


--

HTH,

RD
================================================== ===
Please keep all correspondence within the Group, so all may benefit!
================================================== ===

"KAT" wrote in message
...
In hopes that someone can help me:

I am trying to sort in a column the following in "numerical" order:

A2N1, A2N5, A2N10 (In this order)

It keeps sorting as follows: A2N1, A2N10, A2N5

Is there a way to fix this?

many thanks!


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 in excel 2003 juju Excel Worksheet Functions 1 October 12th 06 11:39 PM
Sorting in Excel - Office Pro 2003 lovetoflyfish New Users to Excel 4 October 3rd 06 11:39 PM
Sorting in Excel 2003 Stars New Users to Excel 2 July 13th 06 10:33 PM
Sorting of data in excel 2003 jonpdavies Excel Discussion (Misc queries) 3 November 23rd 05 03:24 PM
Sorting in Excel 2003 Tonto Excel Discussion (Misc queries) 8 October 3rd 05 04:44 PM


All times are GMT +1. The time now is 01:08 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"