+ Reply to Thread
Results 1 to 5 of 5

Auto Sort problem

Hybrid View

  1. #1
    Registered User
    Join Date
    10-09-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2003
    Posts
    20

    Auto Sort problem

    Hi all

    I have a fairly basic diary system set up. The data is sorted using the following code.(column D is a date)

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Column = 4 Then
        With Range("A1:D" & Range("D65536").End(xlUp).Row)
            .Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlGuess, _
            OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
        End With
        End If
    End Sub
    It works fine, until I want to clear one of the rows of data. It will sort but leaves the blank row at the top of the sheet. Which I dont want.Is the anyway for the sheet to sort including any blank fields so that the row containing the earliest date is at the top of the list?Any help greatfully accepted.Thanks John.
    Last edited by JohnRooney; 03-05-2010 at 11:31 AM. Reason: format wrong

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Auto Sort problem

    I'll take a look. Meanwhile, please change the QUOTE tags above to CODE tags.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Auto Sort problem

    Try this:
    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cell As Range
    
        For Each cell In Target
            If cell.Column = 4 Then
                With Range("A1:D" & Range("D" & Rows.Count).End(xlUp).Row)
                    .Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlYes, _
                        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
                End With
            End If
        Next cell
    
    End Sub

    (Click on EDIT in post #1 to edit the quote tags into code tags)

  4. #4
    Registered User
    Join Date
    10-09-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: Auto Sort problem

    Many thanks- that sorted it- Brilliant! Apologies over the code/quote error.

    I love this place

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Auto Sort problem

    John, crossposting in multiple forums without including links in your posts here is against this forums rules.

    http://www.mrexcel.com/forum/showthread.php?t=452859

    This is a great way to waste people's time, something I'm sure you don't want to do.

    I'm glad we got you worked out here, but please read through the Forum Rules so you can use and follow them effectively. They will only make your use of this resource better.

    Thanks, Jerry.

+ 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