Consulting

Results 1 to 3 of 3

Thread: autofilter dates

  1. #1
    VBAX Tutor
    Joined
    Oct 2007
    Posts
    210
    Location

    autofilter dates

    I want to activate an existing autofilter to sort between two dates. The dates are stored in two cells (lets call them A1 and A2 for this example). I've tried several syntax versions but nothing seems to work. Please help.
    "The amount of stupid people in the world is God's way of punishing the smart people" - protean_being

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    Dates are problemmatical in VBA. The best way that I have foudn is to use the numberformat of the first cell in the range being filtered, like this

    [vba]

    rng.Autofilter Field:=1,Criteria1:= Format(Date, rng.Cells(2,1).Numberformat)
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor
    Joined
    Oct 2007
    Posts
    210
    Location
    thx
    "The amount of stupid people in the world is God's way of punishing the smart people" - protean_being

Posting Permissions

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