Input box to gather date range and sort list using VBA

  • Hi fellow VBA lovers,


    I would love a solution to help me do the follow:


    'Sort' (i.e. push all applicable rows of data which match my criteria to the top of a list, as opposed to just filtering out the irrelevant dates) a list of scheduled courses to the top of my data set based on a date range ('start' and 'end' dates) in Excel 2010. The dates will be provided by the user via an 'Input box' which will pop up at the start when the code is run.


    It would be great if the sorted data could be copied and pasted into a new worksheet called 'sorted data'. Tall order but I would be massively grateful of a solution. Cheers


    Sample In-Put box:
    [TABLE="class: grid, width: 191"]

    [tr]


    [TD="colspan: 2"]Please enter the data range your wish to sort by?:
    [/TD]

    [/tr]


    [tr]


    [td]

    Date range 'Start'

    [/td]


    [td]

    Date range 'End'

    [/td]


    [/tr]


    [tr]


    [td]

    10/08/2014 09:00

    [/td]


    [td]

    14/08/2014 09:30

    [/td]


    [/tr]


    [/TABLE]



    • My data starts in Cell A5
    • The table headers are in row 4
    • My data table has 32 colums
    • and 'X' number of rows (usually about 3,000)


    An example of my data is below 'dates' to sort by will be present in column B.



    [TABLE="class: grid, width: 719, align: left"]

    [tr]


    [td]

    UID ID

    [/td]


    [td]

    Start Date

    [/td]


    [td]

    Last Date

    [/td]


    [td]

    Course UID

    [/td]


    [td]

    Course Title

    [/td]


    [td]

    Status

    [/td]


    [/tr]


    [tr]


    [td]

    100909

    [/td]


    [td]

    10/08/2014 09:00

    [/td]


    [td]

    19/08/2014 17:00

    [/td]


    [td]

    JPCVBA

    [/td]


    [td]

    VBA for complete novice


    [/td]


    [td]

    Cancelled

    [/td]


    [/tr]


    [tr]


    [td]

    100908

    [/td]


    [td]

    12/08/2014 09:30

    [/td]


    [td]

    11/08/2014 12:30

    [/td]


    [td]

    JPCMIR

    [/td]


    [td]

    Baking in the Microwave

    [/td]


    [td]

    Active

    [/td]


    [/tr]


    [tr]


    [td]

    100907

    [/td]


    [td]

    14/08/2014 09:30

    [/td]


    [td]

    12/08/2014 17:30

    [/td]


    [td]

    JPCPLU

    [/td]


    [td]

    Plumbing 101

    [/td]


    [td]

    Cancelled

    [/td]


    [/tr]


    [tr]


    [td]

    100906

    [/td]


    [td]

    02/08/2014 09:30

    [/td]


    [td]

    14/08/2014 17:30

    [/td]


    [td]

    JPCDIY

    [/td]


    [td]

    DIY for the accident prone

    [/td]


    [td]

    Active

    [/td]


    [/tr]


    [tr]


    [td]

    100905

    [/td]


    [td]

    25/08/2014 09:30

    [/td]


    [td]

    14/08/2014 17:30

    [/td]


    [td]

    JPCCHA

    [/td]


    [td]

    How to dance the cha-cha-cha

    [/td]


    [td]

    Cancelled

    [/td]


    [/tr]


    [tr]


    [td]

    100902

    [/td]


    [td]

    18/08/2014 09:30

    [/td]


    [td]

    14/08/2014 17:30

    [/td]


    [td]

    JPCDIY

    [/td]


    [td]

    DIY for the accident prone

    [/td]


    [td]

    Active

    [/td]


    [/tr]


    [/TABLE]

  • Re: Input box to gather date range and sort list using VBA


    Quote from Luke M;725356

    Hello moshjohs.


    This sounds like a perfect place to use an Advanced Filter. Take a look at the attached, or see link for more info.
    http://www.contextures.com/xladvfilter01.html



    Hi Luke, Thank you for your input but this does not solve my problem. My requirements included the filter via vba code and input box for user input of date ranges. Have you got any other solution which covers this?

  • Re: Input box to gather date range and sort list using VBA


    If you look at the file I uploaded, you'll see exactly that. Inputs are taken for the date range, and the filter is performed via VB. I'm not sure what else you are asking.

    Best Regards,
    Luke M
    =======
    "A little knowledge is a dangerous thing."

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!