+ Reply to Thread
Results 1 to 13 of 13

Macro to search through dates and display results based on user input

  1. #1
    Registered User
    Join Date
    08-13-2012
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    16

    Macro to search through dates and display results based on user input

    Hi everyone,

    I would be really grateful for some help, the problem is as follows...

    I have a workbook and sheet1 is updated with data on a daily basis, it consists of four columns and column C contains dates.

    On another sheet I have a nice user interface which I want users ideally to be able to select a month and year and then a button for the users to click and I would like the macro to search through all the data on sheet1 and return the rows which fall into the month and year selected (hope this makes sense). I am just starting off with VB and Excel, well putting my uni skills to the test in a new job. I would be grateful if someone could point me in the right direction, this is the last part of this project I am working on and it is just proving to be a little difficult. Any questions I am more than willing to answer.

    Thanks,
    A

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to search through dates and display results based on user input

    Hi Alan668,

    Try this - it's untested:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    08-13-2012
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Macro to search through dates and display results based on user input

    Hi,

    Thank you so much I will have a try today and let you know, looks good!

  4. #4
    Registered User
    Join Date
    08-13-2012
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Macro to search through dates and display results based on user input

    I keep getting error Next without For? Also, I presume End If should appear after Next? Also, this may be a stupid question but what is r defined as?

    Thanks

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to search through dates and display results based on user input

    Hi Alan668,

    I'm sorry, I forget the End If all the time - I can't seem to develop the habit of automatically entering it when I type If - try this (still untested):


    Please Login or Register  to view this content.
    r is a range - the first so dimensioned - when I just refer to r it's the same as saying r.value!

  6. #6
    Registered User
    Join Date
    08-13-2012
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Macro to search through dates and display results based on user input

    untitledf.jpguntitled.JPG

    Hi,

    Still having problems :/ I have attached screenshots. I would like a user to enter dates where they would like to check availability for, and hit search to return the results in the to the cells in Sheet1. Sheet2 contains the data, which is only test data at the moment however this will be around 1000 dates.

    My code at the moment stands

    Please Login or Register  to view this content.
    I am going terribly wrong somewhere and just cannot seem to get my head around it. Any help would be greatly appreciated as I would like to present on Friday to my boss :/

    Thanks !

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to search through dates and display results based on user input

    Hi Alan668,

    See if this works - if not, let me know the error message you get:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-13-2012
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Macro to search through dates and display results based on user input

    Thanks for your help, unfortunately due to the data I am working with I can only access it at work. I shall try tomorrow and let you know, thanks again!

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to search through dates and display results based on user input

    Ok - I'll look for your post tomorrow.

  10. #10
    Registered User
    Join Date
    08-13-2012
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Macro to search through dates and display results based on user input

    I have the code exact but nothing is happening? I'd like for the user to enter a date range to search (see attached image in above post), for example the user enters 01/08/2012 in cell F7 and the end date in G7, and for the macro to pull all results that are between those dates, I can't even see where it is going wrong :/

  11. #11
    Registered User
    Join Date
    08-13-2012
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Macro to search through dates and display results based on user input

    Finally got it working, this is what I ended up with Thanks again for all your help!!

    Please Login or Register  to view this content.

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to search through dates and display results based on user input

    Glad you got it working! You're welcome!

  13. #13
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Macro to search through dates and display results based on user input

    @ Alan668

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

+ 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