+ Reply to Thread
Results 1 to 2 of 2

Thread: local settings affect autofilter dates with VBA

  1. #1
    Forum Guru
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2003
    Posts
    2,288

    local settings affect autofilter dates with VBA

    This is more for the benefit of my British & European chums:

    When providing a date to autofilter via VBA you must put it in American order. This I think, is because of the way Excel converts the date to a string to put it into the filter 'behind the scenes' (hence not localised properly).

    This wasn't working:
    with range...
        .AutoFilter 11, ">" & Date - 60
    Although the autofilter created looked like it ought to work, indeed recreating the exact same filter manually did work. I found that as the date was > 12 the month & date were effectively coerced into the right place. When I changed the maths to return a day of month less than 12 I saw that the day & month swapped in the custom filter created.
    This does work (showing my thought process):
        .AutoFilter 11, ">" & Month(Date - 60) & "/" & Day(Date - 60) & "/" & Year(Date - 60)
    which can be tidied up:
        .AutoFilter 11, ">" & Format(Date - 60, "mm/dd/yyyy")
    HTH
    CC


    If you feel really indebted please consider a donation to charity. My preferred charity is ActionAid but there are plenty of worthy alternatives.

  2. #2
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,647

    Re: local settings affect autofilter dates with VBA

    Try converting the date to a Long

    with range...
        .AutoFilter 11, ">" & CLng(Date) - 60
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

+ 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.2.0