+ Reply to Thread
Results 1 to 13 of 13

Autofilter on date

  1. #1
    Registered User
    Join Date
    11-06-2011
    Location
    Surrey
    MS-Off Ver
    Excel 2010
    Posts
    51

    Autofilter on date

    guys

    I have a column called Date reported which shows the date and time in the following format

    10/01/2013 15:16:55

    I want to autofilter that column so that it automatically shows only records after the 1st July 2013

    I have tried the following to no avail

    Worksheets("Master").Range("$A:$AB").AutoFilter Field:=5, Criteria1:=">=" & Format("1/7/2013", "DD/mm/yyyy")

    i'm sure its just the way im setting the criteria but cant work it out

    I don't want to change the format of the column to just show the date only i want to see both dated and time but filter by the month

    any ideas

    Mark

  2. #2
    Forum Guru tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Autofilter on date

    Mark,

    Try this:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    11-06-2011
    Location
    Surrey
    MS-Off Ver
    Excel 2010
    Posts
    51

    Re: Autofilter on date

    thanks tigeravatar but it doesn't work

    I tried the following

    Worksheets("Master").Range("$A:$AB").AutoFilter Field:=5, Criteria1:=">=" & DateSerial(2013, 7, 1)

    it applies the autofilter but does not tick any boxes

    if i click on the autofilter manually it has 3 months on the tree May, June and July but none are ticked and no data is show

    im sure its possible but cant work it out

    Mark

  4. #4
    Forum Guru tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Autofilter on date

    In that case I'd have to see a sample file experiencing the issue

  5. #5
    Registered User
    Join Date
    11-06-2011
    Location
    Surrey
    MS-Off Ver
    Excel 2010
    Posts
    51

    Re: Autofilter on date

    Hi tigeravatar

    I have managed to get it working using the following

    Worksheets("Master").Range("$A:$AB").AutoFilter Field:=5, Criteria1:=xlFilterLastMonth, Operator:=xlFilterDynamic

    but this filters for the previous month which is fine if your in august it will work for july but is there a way of specifiying which month it filters?

    mark

    SOLVED

    xlFilterAllDatesInPeriodJuly does the job there is one for every month
    Last edited by wambaugh; 08-14-2013 at 12:12 PM.

  6. #6
    Registered User
    Join Date
    11-06-2011
    Location
    Surrey
    MS-Off Ver
    Excel 2010
    Posts
    51

    Re: Autofilter on date

    GUYS

    what I now need to do is specify which month filter is used depending on a month number in a cell I did the following

    thismonthname="xlFilterAllDatesInPeriod" & worksheets("lookup").range("A2").value

    if the number 7 is in cell A2 the thismonthname = xlFilterAllDatesInPeriodJuly

    I know need to use the varible in the filter I tried as follows

    Worksheets("Master").Range("$A:$AB").AutoFilter Field:=5, Criteria1:=thismonthname, Operator:=xlFilterDynamic

    but it throws up an error

    any ideas how i use the variable?

    Mark

  7. #7
    Forum Guru tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Autofilter on date

    wambaugh,

    Can you please provide a sample file?
    Quote Originally Posted by tigeravatar View Post
    In that case I'd have to see a sample file experiencing the issue

  8. #8
    Registered User
    Join Date
    11-06-2011
    Location
    Surrey
    MS-Off Ver
    Excel 2010
    Posts
    51

    Re: Autofilter on date

    Sample file attached
    click button to run code


    mark


    sample.xlsm

  9. #9
    Forum Guru tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Autofilter on date

    wambaugh,

    When I change the code to the following, it successfully displays only dates that are on or after July 1, 2013:
    Please Login or Register  to view this content.
    I have attached a modified version of your provided sample
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    11-06-2011
    Location
    Surrey
    MS-Off Ver
    Excel 2010
    Posts
    51

    Re: Autofilter on date

    Thanks tigaravatar

    Yes once I changed the dateserial to UK format yes it does work but it doesn't use variables like I was after

    This sheet will be used each month by people who don't know VBA code so I need to be able to pick up the month number from a cell on the lookup sheet

    that way each month they only have to change the month number in cell A1 and it will only show the months data that they have put in the cell

    I don't want to have to change every line of code each month to run a new report

    Also by using the >= operator it will pick up data from any month after July 2013 I just want data from a specific month in a specific year

    I appreciate your help


    Mark

    EDIT

    ok i got it working with variables

    Dim y, m
    y = Year(Worksheets("Lookup").Range("A1").Value)
    m = Month(Worksheets("Lookup").Range("A1").Value)
    With Sheets("Master").Range("$A:$AB")
    .Parent.AutoFilterMode = False
    .AutoFilter Field:=3, Criteria1:=">=" & DateSerial(y, 1, m)
    End With

    i tried the following after Setting cell A1 in Lookup table to "1/6/2013"

    .AutoFilter Field:=3, Criteria1:=">=" & DateSerial(y, 1, m), Operator:=xlAnd, Criteria2:="<=" & DateSerial(y, 30, m)

    but for some reason it shows records from 1st June to the 30th July instead of just JUNES data

    I will need a way of working out how many days in the month specified

    wish I could just workout how to use a variable in the xlFilterAllDatesInPeriod method
    Last edited by wambaugh; 08-16-2013 at 04:58 PM.

  11. #11
    Forum Guru tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Autofilter on date

    Mark,

    Why didn't you say you wanted the filter criteria to be pulled from a cell? What cell will it be pulled from? What is the data that will be in the cell?

    Also, from your original post:
    I want to autofilter that column so that it automatically shows only records after the 1st July 2013
    And from your most recent post:
    Also by using the >= operator it will pick up data from any month after July 2013 I just want data from a specific month in a specific year
    That is easily accomplished, but things would go a lot easier if you would explain these things ahead of time

    Assuming the user is entering the following into sheet 'Lookup' cell A1 and that cell is formatted as General when they do so:
    "July 2013"

    Excel will convert that into a date value of Jul-13 automatically. This VBA code can be used to set the filter:
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    11-06-2011
    Location
    Surrey
    MS-Off Ver
    Excel 2010
    Posts
    51

    Re: Autofilter on date

    Thank you Tigeravatar

    It works a treat

    I just put 1/6/13 into cell A1 on the lookup table and clicking the button just show dta for June

    Your a star sorry for the confusion newbie but learning fast

    Mark

  13. #13
    Forum Guru tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Autofilter on date

    You're very welcome

    If that takes care of your need, please mark this thread as solved.
    How to mark a thread Solved
    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word "Title" you will see a dropdown with the words "No prefix"
    Change to "Solved"
    Click Save

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Autofilter by Date
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-26-2013, 01:39 PM
  2. Replies: 4
    Last Post: 03-16-2013, 08:33 AM
  3. Replies: 2
    Last Post: 07-06-2012, 11:42 AM
  4. Autofilter by Date
    By RagonichaFulva in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-30-2012, 07:57 AM
  5. Autofilter by date
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-03-2011, 10:48 AM

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