+ Reply to Thread
Results 1 to 16 of 16

Macro to filter date range

  1. #1
    Registered User
    Join Date
    02-11-2011
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    32

    Macro to filter date range

    I am trying to create a macro that will filter data between certain dates.

    This date range is determined by the user selected report stage and end dates in column H.

    What I want to happen is when the user enters the report start and end dates - in this case 01/02/2012 to 28/02/2012 - the table (columns A to E is filtered for this date range.

    See attached file.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Macro to filter date range

    Hi try this
    Please Login or Register  to view this content.
    p.s. change the place of end data (cells h2) into first row becouse the sorting could hide the row with this value.
    Last edited by tom1977; 06-01-2012 at 06:11 AM.
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  3. #3
    Registered User
    Join Date
    02-11-2011
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Macro to filter date range

    Quote Originally Posted by tom1977 View Post
    Hi try this
    Please Login or Register  to view this content.
    p.s. change the place of end data (cells h2) into first row becouse the sorting could hide the row with this value.

    Tom,

    i have tried this, it hides all of my data except for row1.

  4. #4
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Macro to filter date range

    For me it works (look into attachment)
    Attached Files Attached Files
    Last edited by tom1977; 06-01-2012 at 08:52 AM.

  5. #5
    Registered User
    Join Date
    02-11-2011
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Macro to filter date range

    Quote Originally Posted by tom1977 View Post
    For me it works (look into attachment)
    Very strange. When I run the macro in you attached file I get this.
    Attached Images Attached Images

  6. #6
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Macro to filter date range

    Please check again my attachment (probably I have uploaded not correct one .)

  7. #7
    Registered User
    Join Date
    02-11-2011
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Macro to filter date range

    No sorry, it iis not working for me.

  8. #8
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Macro to filter date range

    Are You sure that the format of date in cells H1 and H2 is in correct format?

    or
    the date You typed in was in range?
    Last edited by tom1977; 06-01-2012 at 09:23 AM.

  9. #9
    Registered User
    Join Date
    02-11-2011
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Macro to filter date range

    Quote Originally Posted by tom1977 View Post
    Are You sure that the format of date in cells H1 and H2 is in correct format?

    or
    the date You typed in was in range?
    I believe so, I have just opened your attached file and run the macro?

  10. #10
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Macro to filter date range

    So I do not have idea. Sorry. When I open this it works...

  11. #11
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Macro to filter date range

    Hi Excel_Monkey,

    As pointed out by Tom, I would check to ensure your dates are indeed dates.

    To check a date, use =ISNUMBER(Cell Reference)

    If it is a date, the answer is TRUE, if not, FALSE

    If you find out they are not dates and just showing as dates but really text, highlight the column of dates, Data Tab >> Text to Columns >> Next >> Next >> Date MDY (or DMY) >> Finish.
    HTH
    Regards, Jeff

  12. #12
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Macro to filter date range

    change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  13. #13
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Macro to filter date range

    Hi Excel Monkey,

    Have you ever worked with Advanced Filters? They do what I think you are looking for. See http://www.contextures.com/xladvfilter01.html and look down the page to Advanced Filter Criteria Examples.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  14. #14
    Registered User
    Join Date
    02-11-2011
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Macro to filter date range

    Quote Originally Posted by JosephP View Post
    change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    That Works! Wow, thank you, this has been driving me mad.


    Marvin, I shall also look into the advanced filters.

  15. #15
    Registered User
    Join Date
    06-23-2014
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    1

    Re: Macro to filter date range

    Sorry to bother you, but why "Value2" and not "Value"?

  16. #16
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Macro to filter date range

    value2 returns the date as a Double not a date data type which can be misinterpreted when used as a string

+ 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