+ Reply to Thread
Results 1 to 4 of 4

Sort but ignore cells with ""

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-02-2007
    Location
    Leeds, England
    MS-Off Ver
    MS Office 2007
    Posts
    134

    Sort but ignore cells with ""

    Hi All,

    I have a set of cells that I want to sort within a macro. I want these to be sorted ascending but some of the cells contain "" to enable me to have blank looking cells. When I sort the cells the ones with "" come before those beginnign with A. Is there a way to avoid this?

    This is the code I have currently.

    Range("B9:H43").Sort Key1:=Range("B9"), Order1:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
    Thanks
    dvent

  2. #2
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671
    They come after the last ones, do they not?

    A--qwerty
    B--home
    ""--Friend
    D--People

    End up in

    A--qwerty
    B--home
    D--People
    ""--Friend
    Last edited by rwgrietveld; 12-10-2008 at 07:40 AM.
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  3. #3
    Forum Contributor
    Join Date
    11-02-2007
    Location
    Leeds, England
    MS-Off Ver
    MS Office 2007
    Posts
    134
    it seems that if i enter ="" manually, these cells end up at the bottom.

    but when "" is enterred into the cells by a previous macro, they stay at the top of the list. very strange?!

  4. #4
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671
    NOTE that ="" is not the same as a blank cell.

    See this:
    ?ASC("=""")
    61
    ?ASC("a")
    97
    ?ASC("A")
    65
    ?ASC("Z")
    90
    ?ASC("z")
    122

    The ASCI code of a blank does not exists and therefore it is placed at the bottom.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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