+ Reply to Thread
Results 1 to 7 of 7

simple date comparison - code review

  1. #1
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    simple date comparison - code review

    Can someone review my code below and let me know if you see anything I'm doing wrong? I'm trying to compare 2 dates, but I keep getting "Invalid procedure call or argument" on my first If line. When I step through, startDate = 6/29/2013 and compareToDate = 7/1/2013. I'm casting both as dates, what else am I missing?

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: simple date comparison - code review

    Try the following tested in Excel 2003, which should get you pointed in the right direction:
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Re: simple date comparison - code review

    Thanks for the response, but my dates are valid. Users can't enter invalid dates as I have data validation set on all date cells. When I step through and check my variables, they're set to valid dates. I'm starting to wonder if the problem lies elsewhere because my casting is right and the dates are indeed valid

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: simple date comparison - code review

    It was worth a try. The routine works for me when I substitute generic code for your project specific code.
    My next suggestion is to remove the offending code using 'Conditional Compilation' until you find what is causing the error.

    Please Login or Register  to view this content.
    You will know that 'Conditional Compilation' removed the code, when you try to set a 'Breakpoint' in the offending section and VBA won't let you set the 'Breakpoint'.

  5. #5
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Re: simple date comparison - code review

    Ya this method gets called through other methods, so I think I have some further investigating to do. Although, everything was fine until I wrote and called this!

  6. #6
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: simple date comparison - code review

    In the Excel 2003 debugger you can access the call stack which can show you where the error came from:
    a. In the debugger menu View > Call Stack or
    b. Control L

  7. #7
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Re: simple date comparison - code review

    Cool thanks I will look at this when I get home this evening

+ 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. Date Comparison
    By treeantz in forum Excel General
    Replies: 1
    Last Post: 07-04-2011, 12:16 AM
  2. comparison with simple 'if' formula
    By BigPole in forum Excel General
    Replies: 3
    Last Post: 05-14-2010, 08:44 AM
  3. VBA: Date Comparison
    By dzuy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-29-2006, 11:55 AM
  4. [SOLVED] Date comparison
    By Darkdrew in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-23-2006, 12:25 PM
  5. simple MAX + comparison formula
    By j0e in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-04-2005, 02:25 AM

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