+ Reply to Thread
Results 1 to 5 of 5

Date AutoFilter Not Working

  1. #1
    Registered User
    Join Date
    08-18-2017
    Location
    London, England
    MS-Off Ver
    Office 2010
    Posts
    1

    Date AutoFilter Not Working

    Purpose of my script:

    To filter Column C3 of my spreadsheet to display only the future dates of meetings

    Due to my region is in UK, I understands that the Excel Macro needs special coding to change the date format to DDMMYYYY

    My code:
    Please Login or Register  to view this content.
    Issue: When I run the script, the spreadsheet automatically jumps to the next empty field and does not perform what I intend to do.

    I am a very newbie in Excel VBA appreciate for your kind assist to point out and correct whatever mistakes in my code? Many thanks.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Date AutoFilter Not Working

    Please Login or Register  to view this content.
    It might not work as dates are nightmare to deal with. The criteria also works well with texts, so perhaps changing it in to text format will work.

  3. #3
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Date AutoFilter Not Working

    Some problems:

    1. You are building the date from dDate, which is an unset variable instead of Date, which is a function that returns the system date.
    2. You should add CLng() around dDate to ensure it is coerced to long integer format (and it shows more clearly what you are aiming to do)
    3. The function DateSerial is being used the wrong way round. It should be DateSerial(Year,Month,Day)
    4. (optional) You can just go straight to lDate = CLng(Date) since VBA will convert the system date format to long integer using the system date format.
    5. You are passing the criteria as a string, and using dDate instead of lDate


    Implementing the changes should fix the code:

    Please Login or Register  to view this content.
    Last edited by Stormin'; 08-18-2017 at 07:17 AM.
    Design everything to be as simple as possible, but no simpler.

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Date AutoFilter Not Working

    Hi,

    If you are using a Long variable, you can skip a conversion by using CLng instead of CDbl.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  5. #5
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Date AutoFilter Not Working

    Oops, nice catch nitwit. My mistake. I have edited my code above.

+ 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. Autofilter not working
    By Zeos6 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-04-2013, 03:43 PM
  2. Replies: 4
    Last Post: 03-16-2013, 08:33 AM
  3. Autofilter not working
    By psbailey42 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-26-2013, 07:15 AM
  4. Replies: 2
    Last Post: 07-06-2012, 11:42 AM
  5. autofilter not working
    By ACTBOB in forum Excel General
    Replies: 2
    Last Post: 07-21-2006, 05:20 PM
  6. [SOLVED] Autofilter not working correctly...
    By Emily in forum Excel General
    Replies: 0
    Last Post: 01-11-2006, 06:40 PM
  7. Applying autofilter via VBA Not working
    By wschanks in forum Excel General
    Replies: 1
    Last Post: 05-02-2005, 05:08 PM
  8. Autofilter Not working
    By cyndi in forum Excel General
    Replies: 3
    Last Post: 02-14-2005, 07:06 PM

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