Results 1 to 3 of 3

Thread: [RESOLVED] Filtered Date selection?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Posts
    167

    Resolved [RESOLVED] Filtered Date selection?

    Guys,

    Can you help me, I have written some code to filter some data by date.


    Code:
    ' Sets the Date criteria for searching
        TDate = Format((Now - 2), "dd/mm/yyyy")
    ' Filters for all receipts that are older than 24 hours
        Selection.AutoFilter Field:=7, Criteria1:="<=" & TDate
    All data is in the correct format, and when the code is run the filter is activated with the relevant search criteria but nothing is displayed in the data file.

    However when I go into the filter manually on the data file, all the coded criteria is correct and when I confirm manually the filtered data is displayed.

    Why is the code not automatically displaying the data?

    Thanks

    SJ

  2. #2
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Filtered Date selection?

    Try this:
    Code:
    Selection.AutoFilter Field:=7, Criteria1:="<=" & CDbl(Now - 1)
    That is filter for record older than 24 hours from current date-time (Now).

    If the filtered column contains only dates (no time portion) and you want to filter for records that is on any day before yesterday then use this:
    Code:
    Selection.AutoFilter Field:=7, Criteria1:="<=" & CDbl(Date - 2)
    or
    Code:
    Selection.AutoFilter Field:=7, Criteria1:="<" & CDbl(Date - 1)
    Ps. If you need the date with time portion then use Now() function, if just need the date without time then use Date() function.
    Now = Date + Time
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Posts
    167

    Re: Filtered Date selection?

    Anhn,

    Thanks it worked a treat.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width