Closed Thread
Results 1 to 13 of 13

Keeping blank rows when sorting

Hybrid View

  1. #1
    Registered User
    Join Date
    04-21-2008
    Posts
    8

    Keeping blank rows when sorting

    I have a spreadsheet that I want to keep the blank rows that seperate the data for asthetic reasons. Can I sort just the rows with data in them and still keep the blank rows where they are?

    Thanks for your assistance

  2. #2
    Forum Contributor EdMac's Avatar
    Join Date
    01-23-2006
    Location
    Exeter, UK
    MS-Off Ver
    2003
    Posts
    1,264
    I presume you have groups of data separated by blanks and you want to sort within the sets.

    I think you can only do this by sorting each set of rows individually - Excel would not know where to put blanks otherwise
    Ed
    _____________________________
    Always learning, but never enough!
    _____________________________

  3. #3
    Registered User
    Join Date
    11-16-2007
    Posts
    26
    Quote Originally Posted by EdMac
    I presume you have groups of data separated by blanks and you want to sort within the sets.

    I think you can only do this by sorting each set of rows individually - Excel would not know where to put blanks otherwise
    I have an idea, but don't know much about changing the filter settings. So perhaps you know.

    Is it possible to have it filter for things in common?

    For example, you have 2 variations of inputs, and create a 3rd.
    a,
    b,
    a, b

    The idea being that you would make the "blank" row a, b and change the font color to make it appear hidden.

    Then when you select either a, or b, it could also recognize either value in the "blank" and leave that in the chart? The challenge would be if there were a lot of variations, then that blank cell would need to contain all of them.

  4. #4
    Forum Contributor EdMac's Avatar
    Join Date
    01-23-2006
    Location
    Exeter, UK
    MS-Off Ver
    2003
    Posts
    1,264
    Difficult to visualise what you want to achieve - can you post an example? You need to ZIP it first

  5. #5
    Registered User
    Join Date
    11-16-2007
    Posts
    26
    Here is a model of what I mean for the filter allowing the "blank" rows. Maybe it's better to refer to them as the universal value row?
    Attached Files Attached Files

  6. #6
    Forum Contributor EdMac's Avatar
    Join Date
    01-23-2006
    Location
    Exeter, UK
    MS-Off Ver
    2003
    Posts
    1,264
    I don't think that what you want is possible (I'm not sure what purpose it serves either).

    Perhaps if you were to describe the problem you want to solve, there might be another way to achieve it.

  7. #7
    Registered User
    Join Date
    04-21-2008
    Posts
    8

    I've attached the worksheet

    Here is the worksheet I need to sort and keep the blank rows where they are. Any suggestions on how to do this better?
    Keep i nmind this is to display golf scores as they are coming in so it will be updated throughout the day.
    Attached Files Attached Files

  8. #8
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320
    the simplest way is to reference cells on another sheet
    do your sorting on the other sheet.

    see sheet 2
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    12-26-2013
    Location
    Chicago, Il
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Keeping blank rows when sorting

    I had an idea and I think I have the code that works. I created a series number column and used Ctrl down to find where the data ranges and blank lines were, then numbered each set as a series. It let me sort within the data sets and keep the blank lines exactly where they were.
    Sub SortBySeries()
    Dim FinalRow As Long
    Dim i As Long
    Dim RangeEnd As Long
    Dim RangeStart As Long
    Dim BlankSwitch As Boolean
    
    'determines last row of data in the desired range
    Range("a1048576").Select
    Selection.End(xlUp).Select
    FinalRow = Selection.Row
    Range("a:a").Insert shift:=xlToRight
    Range("b2").Select
    i = 2
    Range("a1").Value = 1
    BlankSwitch = False
    
    'creates a column with the series number for each set of data
    Do While ActiveCell.Row < FinalRow
    If BlankSwitch = False Then
    'tests for single line of data in the range, which will mess up the system
    If ActiveCell.Offset(1, 0).Value <> 0 Then
    RangeStart = Selection.Row
    Selection.End(xlDown).Select
    RangeEnd = Selection.Row
    BlankSwitch = True
    Else
    'numbering in filled range
    RangeStart = Selection.Row
    RangeEnd = Selection.Row
    BlankSwitch = True
    End If
    Else
    'numbering in range with no data
    RangeStart = Selection.Row + 1
    Selection.End(xlDown).Select
    RangeEnd = Selection.Row - 1
    BlankSwitch = False
    End If
    
    Range("a" & RangeStart, "a" & RangeEnd).Value = i
    i = i + 1
    Loop
    
    'sorts by series number to preserve blank rows and related data, then by 2 other criteria
    Cells.Select
        ActiveWorkbook.Worksheets(1).Sort.SortFields.Clear
        ActiveWorkbook.Worksheets(1).Sort.SortFields.Add Key:=Range("A:A"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets(1).Sort.SortFields.Add Key:=Range("E:E"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets(1).Sort.SortFields.Add Key:=Range("H:H"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets(1).Sort
            .SetRange Range("A1:P" & FinalRow)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    
    End Sub

  10. #10
    Registered User
    Join Date
    07-23-2014
    Location
    nicosia,cyprus
    MS-Off Ver
    MS Office 13
    Posts
    4

    Re: Keeping blank rows when sorting

    Hello everyone,

    I wanted to ask something as well i am trying to create a macro that sorts rows based on value of 2 columns, but every time that value changes in either of them to leave an empty row between them.
    Is that possible? In simple words i want to separate my rows and sorting them out alphabetically.

    Kind regards, Andriano

  11. #11
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Keeping blank rows when sorting

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

Closed 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