+ Reply to Thread
Results 1 to 15 of 15

Code Help Needed to Sort Data

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-07-2005
    Location
    England
    MS-Off Ver
    Office 2019 Enterprise
    Posts
    473

    Re: Code Help Needed to Sort Data

    Hi Lynn,

    What do you mean when you say 'need to have the capability of picking what dates from column P I want to select to sort' ?

    Do you mean a date range (i.e 01-jan-11 to 30-Jan-11) or a list of dates (01-jan-11, 05-jan-11, 10-jan-11)?

    John

  2. #2
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: Code Help Needed to Sort Data

    Hi Lynn

    It looks as if you need Advanced Filter after you set the range of dates you want to examine.

    In the attached workbook, enter the earliest date you want to retrieve in cell G6 on Sheet "Contact Due Dates", and in cell H6 enter the latest date you want to retrieve.

    Then click the button Extract Data, and those records will be extracted for you and sorted in ascending order by Lowest Next Contact Date.

    The code attached to the button is
    
    Option Explicit
    
    Sub ExtractData()
        Dim lr As Long
        Dim ws As Worksheet, wsc As Worksheet
        Dim myrange As Range
        
        Set ws = Sheets("Contact Due Dates")
        Set wsc = Sheets("Client Files")
        
        If Application.Count(ws.Range("G6:H6")) <> 2 Then Exit Sub
        Application.ScreenUpdating = False
        lr = wsc.Cells(Rows.Count, 1).End(xlUp).Row
        wsc.Activate
        Set myrange = wsc.Range(Cells(1, 1), Cells(lr, "P"))
        ws.Activate
        
        myrange.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=ws.Range( _
                                                                    "Crit"), CopyToRange:=ws.Range("Destination"), Unique:=False
        lr = ws.Cells(Rows.Count, 1).End(xlUp).Row
        If lr > 8 Then
            ws.Range("A8:H" & lr).Sort Key1:=ws.Range("H8"), Order1:=xlAscending, Header:=xlYes
        End If
        Application.ScreenUpdating = True
    End Sub
    You could also simplify your formula in cell M2 of Client files
    FROM
    =IF(I2="","",IF(J2="","",IF(J2=1,I2+7,IF(J2=2,I2+30,IF(J2=3,I2+90,IF(J2=4,I2+182,IF(J2=5,I2+365,IF(J2=6,"Case Closed",""))))))))
    
    TO
    =IF(OR(I2="",J2=""),"",IF(J2=6,"Case Closed",I2+CHOOSE(J2,7,30,90,182,365)))
    Attached Files Attached Files
    --
    Regards
    Roger Govier
    Microsoft Excel MVP

  3. #3
    Registered User
    Join Date
    05-10-2011
    Location
    Tampa, Florida
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: Code Help Needed to Sort Data

    I can't seem to find the extract data button that the code is tied to. Where is it?
    Thanks.

  4. #4
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: Code Help Needed to Sort Data

    Quote Originally Posted by Lynn McCurdy View Post
    I can't seem to find the extract data button that the code is tied to. Where is it?
    Thanks.
    I have made it bigger and made the text Red.
    The button is located over the top of cells E5:F6

    If for some reason the button isn't on your copy, use the keyboard shortcut I have assigned to the macro of Control+Shift+E

    Or, Tools>Macros>highlight "Extract Data">Run
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    05-10-2011
    Location
    Tampa, Florida
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: Code Help Needed to Sort Data

    List of dates.

+ 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