+ Reply to Thread
Results 1 to 4 of 4

Ignore Blank Cells When Sorting

  1. #1
    Forum Contributor
    Join Date
    11-30-2020
    Location
    Ny
    MS-Off Ver
    Office 365
    Posts
    188

    Ignore Blank Cells When Sorting

    In the column I'm trying to sort, occasionally there are cells that contain a zero. Is there a way to omit them from the sorting macro and place them at the end. the macro I have written is as follows:

    Sub SortRankings()

    With ActiveSheet.Sort
    .SortFields.Clear
    .SortFields.Add2 Key:=Range("AB7:AB26"), _
    SortOn:=xlSortOnValues, _
    Order:=xlAscending, _
    DataOption:=xlSortNormal
    .SetRange Range("W7:AB26")
    .Header = xlNo
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With


    End Sub


    Ay help will be appreciated, Thanks!

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,039

    Re: Ignore Blank Cells When Sorting

    Administrative Note:

    We would very much like to help you with your query, however we recommend that you include code tags around your code.

    Please take a moment to add the tags. Posting code between [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Guideline #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here.

  3. #3
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,531

    Re: Ignore Blank Cells When Sorting

    If all the cells in column AB have numerical values (none are empty), you can remove 0(zero) from these cells before sorting, then sort the range and finally restore zeros in the empty cells. Review the following example:
    Please Login or Register  to view this content.
    Artik

  4. #4
    Forum Contributor
    Join Date
    11-30-2020
    Location
    Ny
    MS-Off Ver
    Office 365
    Posts
    188

    Re: Ignore Blank Cells When Sorting

    Thanks I'll give it a try!

+ 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. [SOLVED] Ignore Blank cells and jump to next non blank cell
    By yarlachiru in forum Excel General
    Replies: 18
    Last Post: 05-26-2021, 06:28 AM
  2. Sorting Column with formula, ignore blank cells
    By nickpavlov in forum Excel General
    Replies: 2
    Last Post: 05-01-2021, 11:32 AM
  3. Replies: 2
    Last Post: 08-13-2018, 02:30 AM
  4. [SOLVED] Ignore blank cells with formulas or ignore NA() in a formula
    By guiismiti in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 03-24-2016, 02:13 PM
  5. Ignore blank cells and truly blank cells in named range?
    By hschillig in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-13-2014, 02:56 PM
  6. Replies: 5
    Last Post: 05-18-2013, 07:49 PM
  7. How can I make a macro ignore blank cells? - Blank Cells have formulas
    By mz1161 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-30-2013, 08:54 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