Results 1 to 13 of 13

Thread: Excel date problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    20

    Excel date problem

    Am using a command button and autofilter to only see things with todays date.

    VB Code:
    1. Sub TodaysFault()
    2.     Sheets("Database").Select
    3.     Selection.AutoFilter Field:=3, Criteria1:=Format(Now, "mm/dd/yyyy"), Operator:=xlAnd
    4. End Sub

    I've had a browse around the forums and found the
    VB Code:
    1. Criteria1:=Format(Now, "mm/dd/yyyy")
    part. Got a feeling this is where I'm going wrong. Basically the Criteria1:= needs to be todays date and then once the macro has run autofilter only shows todays date of parts that I have in my sheet.

  2. #2

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    20

    Re: Excel date problem

    Should I have done this in VBA?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    20

    Re: Excel date problem

    Just messing around with it would it have anything to do with the date format?

  4. #4

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    20

    Re: Excel date problem

    Just need to know the code for todays date, tried google and going through the old forum posts and have nothing. Any help will be appreciated!

  5. #5

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    20

    Re: Excel date problem

    Anyone else got any idea?

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Excel date problem

    Today's date is
    VB Code:
    1. Format(Now, "mm/dd/yyyy")
    Are you doing this in VB6 or Excel VBA?

  7. #7
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Excel date problem

    Criteria1:=Format(Now, "mm/dd/yyyy")
    Seems you already had your answer in your question. Seems this is Excel -VBA 'cause of the "Sheets("Database").Select"


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  8. #8

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    20

    Re: Excel date problem

    Excel VBA, still having no luck

  9. #9
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818

    Re: Excel date problem

    Have you got your days and months the correct way around for your data ?

    i.e. would this work instead :

    VB Code:
    1. Format(Now, "dd/mm/yyyy")

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Excel date problem

    Moved
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    20

    Re: Excel date problem

    Would it have anything to do with the format of the cell or anything like that? The date is in the correct format as far as I can see, dd/mm/yyyy and this is how I have it in the code.

  12. #12
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818

    Re: Excel date problem

    What ARE the cells formatted as ?

  13. #13
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Excel date problem

    I think you either

    a) need to turn the filter off then back on again
    or
    b) refresh/requery the autofilter

    Either way you'd need to do call that as the workbook/sheet opens.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

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