+ Reply to Thread
Results 1 to 3 of 3

Date Comparison in VBA versus if statement on sheet not equivalent?

  1. #1
    Registered User
    Join Date
    07-30-2014
    Location
    Frederick, Maryland
    MS-Off Ver
    Professional Plus 2010
    Posts
    12

    Date Comparison in VBA versus if statement on sheet not equivalent?

    I am looping through several dates and my goal is, if the date is within the last 24 hours, then I want to sum a number corresponding to that date with all the other data from that day (to eventually find the average). However I am getting not getting what I expect using the comparison in VBA - the if statement is always true when I use a greater than comparison.

    When I do a "=IF(H6>I6,1,0)" with the same dates as a sheet formula, it has the correct indication whether H6 is after I6 or not. The following code however does not give an equivalent:

    Please Login or Register  to view this content.
    Any help is appreciated.

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Date Comparison in VBA versus if statement on sheet not equivalent?

    How are compdate and lday declared? They should be Date types, not Variant or String.
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    07-30-2014
    Location
    Frederick, Maryland
    MS-Off Ver
    Professional Plus 2010
    Posts
    12

    Re: Date Comparison in VBA versus if statement on sheet not equivalent?

    I did not specifically declare them as anything other than with the Format. When I explicitly declare them as Dates, I get the correct outcome! Thanks!

+ 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. Replies: 5
    Last Post: 01-05-2015, 03:57 PM
  2. Color Code Actual Date versus Due Date ( Red, Yellow, Green )
    By Bfisher74 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-28-2013, 10:10 AM
  3. [SOLVED] 3,000 Tables versus 3,000 Worksheets versus 3,000 Workbooks
    By StevenM in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-18-2012, 03:15 AM
  4. If/AND/OR Statement or Equivalent Question
    By ACEMAN3131 in forum Excel General
    Replies: 3
    Last Post: 12-10-2011, 09:01 PM
  5. last column equivalent to my last row statement
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-08-2011, 08:15 AM
  6. Date Comparison and IF statement
    By Holly in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-18-2006, 09:10 PM
  7. Replies: 5
    Last Post: 07-05-2005, 05:05 PM

Tags for this Thread

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