+ Reply to Thread
Results 1 to 6 of 6

Thread: Sorting numbers with #N/A

  1. #1
    Registered User
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    Excel 2010
    Posts
    40

    Sorting numbers with #N/A

    I am trying to set up a macro to sort descending but to have any cells that are "N/A" to be sorted at the bottom.

    An example:

    Data:
    5
    7
    4
    N/A

    When using descending "Sort" in excel, the data is arranged:
    N/A
    7
    5
    4

    I would like it to sort as follows:
    7
    5
    4
    N/A

    Thanks!

  2. #2
    Registered User
    Join Date
    05-15-2011
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2007, Excel MAC 2008
    Posts
    29

    Re: Sorting numbers with #N/A

    Hi dluhut

    I would always look at the errors to see why you are getting them and look to Excel to replace them with either zeros or blanks. Then you can sort away without any problems.

    Try this post here for some guidance

    Hope that helps
    Barbara

    http://howtoexcelatexcel.com

  3. #3
    Forum Guru Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    Excel 2010
    Posts
    1,249

    Re: Sorting numbers with #N/A

    Change your formula in that column to =IfErr(yourcurrentformula,0).

    If you can't use zero, then you could use a negative number like -999999 or something.

    Or, if you need to preserve the content of the column in question, you could use a helper column and use =IfErr(A1,0) and then sort by the helper column.
    Last edited by Whizbang; 06-23-2011 at 05:09 PM.

  4. #4
    Registered User
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Sorting numbers with #N/A

    Thanks to those who replied.

    To be more specific, I've attached a file so that you guys could understand.

    Noticed that on the file, I filtered on Column E to purposefully hide some rows, reason being is that in the original file that I'll be doing, I have a code that filters showing only datas that I want to see based on the dropdown list, and then follow by another macro/code that will do the sorting.

    The sorting will then be like what I've described above, which is putting numbers first in descending orders before the #N/A.

    Below are the codes that I need to tweak in order to let the sorting works after I've done filtering.

    Sub SELECT_PLATINUM_CLUB()
      Selection.AutoFilter _
            Field:=1, _
            Criteria1:=ThisWorkbook.Worksheets("drop down list").Range("d2").Value, _
            Operator:=xlAnd
            
      Dim rngToSort   As Range
        Dim naRow       As Long
        Dim LastRow     As Integer
    
        LastRow = Range("B" & Rows.Count).End(xlUp).Row
    
        Set rngToSort = Range("B16:P" & LastRow)
        
        With rngToSort
            .Sort .Cells(2, 12), 1, Header:=1 'first sort Col M by ascending
            On Error Resume Next
            naRow = .SpecialCells(2, 20).Row
            If naRow = 0 Then naRow = .SpecialCells(-4123, 20).Row
            On Error GoTo 0
            If naRow Then
                With .Cells(1, 1).Resize(naRow - .Row, .Columns.Count)
                    .Sort .Cells(2, 12), 2, Header:=1 'then sort Col M by descending
                End With
            Else
                .Sort .Cells(2, 12), 2, Header:=1 'if no error cells, sort again Col M by descending
            End If
        End With
    
    End Sub
    Attached Files Attached Files

  5. #5
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    PA
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    926

    Re: Sorting numbers with #N/A

    Dluhut,

    You need to read the forum rules:

    You should post the link when you cross post a question on another Forum.

    Here is the link:
    http://www.ozgrid.com/forum/showthread.php?t=155406

    ...
    Thank You, Mike

    Some Helpful Hints:

    1. New members please read & follow the Forum Rules
    2. Use Code Tags...Place[code]Before the first line and[/code] After the last line.
    3. If you are pleased with a solution mark your post SOLVED.
    4. Thank those who have help you by clicking the scales at the top right of the post.

    Here...

  6. #6
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    PA
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    926

    Re: Sorting numbers with #N/A

    Any Mod,

    You can mark this post solved as per the link I provided in my last post the user has a working script from the other forum.

    Thank You, Mike

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0