+ Reply to Thread
Results 1 to 7 of 7

Sorting numbers

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-21-2010
    Location
    Chicago,Illinois
    MS-Off Ver
    Excel 2019
    Posts
    206

    Sorting numbers

    I have a column with these numbers

    421
    102
    883
    973
    487
    620
    146
    218


    I would like to sort them from high to low (in terms of left to right) Ex...
    124
    012
    388
    379
    478...etc
    Last edited by Jordans121; 08-07-2013 at 05:12 PM.

  2. #2
    Valued Forum Contributor Melvinrobb's Avatar
    Join Date
    06-19-2012
    Location
    Manitoba, Canada
    MS-Off Ver
    Excel 2013
    Posts
    1,128

    Re: Sorting numbers

    Are they all 3 characters long?
    Please click the * icon below if I have helped.

  3. #3
    Forum Contributor
    Join Date
    01-21-2010
    Location
    Chicago,Illinois
    MS-Off Ver
    Excel 2019
    Posts
    206

    Re: Sorting numbers

    Yes. All numbers are 3 characters long and are located in column B (from row 2:1001).

  4. #4
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Sorting numbers

    Is this is what you are after?

    Public Function ArraySort(ByVal vValue As Variant) As String
    
    Dim strv As String, strtemp As String, strFinal As String
    Dim i As Integer, x As Integer, y As Integer
    Dim strArray As Variant
    
    strv = vValue
    
    For i = 1 To Len(strv)
        strtemp = strtemp & "," & Mid(strv, i, 1)
    Next i
    
    strtemp = Right(strtemp, Len(strtemp) - 1)
    strArray = Split(strtemp, ",")
    
    For x = LBound(strArray) To (UBound(strArray) - 1)
        For y = (x + 1) To UBound(strArray)
            If strArray(x) > strArray(y) Then
                strtemp = strArray(x)
                strArray(x) = strArray(y)
                strArray(y) = strtemp
                strtemp = ""
            End If
        Next y
    Next x
    
    For i = LBound(strArray) To UBound(strArray)
        strFinal = strFinal & strArray(i)
    Next i
    
    ArraySort = strFinal
    
    End Function
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    01-21-2010
    Location
    Chicago,Illinois
    MS-Off Ver
    Excel 2019
    Posts
    206

    Re: Sorting numbers

    Yes. Thanks
    Last edited by Jordans121; 08-07-2013 at 05:11 PM.

  6. #6
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Sorting numbers

    ArraySort is an User-Defined Function. Just copy the code to your workbook.

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Sorting numbers

    If they wont sort as numbers, that means they are text, looking like numbers, and should sort as such, when you sort them.

    If this is not happening, can you upload a sample workbook, showing what you are working with?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Help sorting numbers
    By digger12 in forum Excel General
    Replies: 1
    Last Post: 08-03-2011, 06:54 AM
  2. Replies: 5
    Last Post: 07-15-2006, 08:30 PM
  3. [SOLVED] Sorting numbers with differing numbers of digits
    By Trudy in forum Excel General
    Replies: 5
    Last Post: 03-04-2006, 08:35 AM
  4. Sorting texts and numbers as if it was all numbers
    By Werner in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-07-2005, 04:05 PM
  5. sorting the row by numbers
    By Jen in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-12-2005, 03:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1