+ Reply to Thread
Results 1 to 4 of 4

If condition satisfied but ignored

  1. #1
    Registered User
    Join Date
    07-08-2019
    Location
    perth
    MS-Off Ver
    365
    Posts
    2

    Unhappy If condition satisfied but ignored

    OK this is annoying me.
    The If condition is satisfied but jumps to the next one where the (O_Hrs + Time_Acc >8) when in fact it satisfies the (O_Hrs + Time_Acc <=8)

    What on earth am i missing.

    Please Login or Register  to view this content.


    VBA If condition fail.png
    Last edited by remkin76; 07-08-2019 at 11:48 PM.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: If condition satisfied but ignored

    Quote Originally Posted by remkin76 View Post
    OK this is annoying me.
    The If condition is satisfied but jumps to the next one where the (O_Hrs + Time_Acc >8) when in fact it satisfies the (O_Hrs + Time_Acc <=8)
    Are you sure it is being satisfied? Hard to say for sure without seeing any data, but if you are testing a REAL time against 8, then this is probably where you are getting mixed up.

    What you need to understand about dates and times in excel is…

    a date is just a number representing the number of days passed since 1/1/900...and then formatted in a way that we recognize as a date. So, for instance, today (Tue 09 Jul 2019) is actually 43655

    Time is actually a decimal part of 1 (day), so 06:00 AM is 0.25, 12 noon is 0.5 and 18:00 (or 6 PM) is 0.75

    So, having said all that, 8 (am) is actually 0.333 and 8 (pm) is really 0.666
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    07-08-2019
    Location
    perth
    MS-Off Ver
    365
    Posts
    2

    Re: If condition satisfied but ignored

    Thanks Ford,
    Is definitely satisfied as the values are Dim as Double and the rest of the code works with these values. If you look at the picture I posted it has the watch values. The excel cells are definitely not formatted as dates. Can you see the watch values in the picture. Whats actually worse for me is that the next condition which is greater than 8 has been satisfied.

    I have several other sheets which are converting the values to numbers, the dates are not used as reference in formulas I use some trickery to determine if the dates are the same or not an convert the times to number specifically for calculations. The timekeeping software also rounds to the nearest 0.25 so we cant have a value of anything other than .25 .50 or .75 so we inherently cant be that close to 8

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: If condition satisfied but ignored

    Pics are often hard to make out. I suggest that you upload a small (clean) sample workbook (not a pic) of what you are working with, and what your expected outcome would look like.

+ 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: 7
    Last Post: 06-01-2015, 06:05 PM
  2. Extract values if condition is satisfied
    By bjnockle in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 08-26-2014, 08:39 AM
  3. Replies: 2
    Last Post: 08-01-2011, 03:22 PM
  4. Replies: 8
    Last Post: 05-06-2011, 08:25 AM
  5. [SOLVED] Deleting columns if condition is satisfied
    By kent-dk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-15-2006, 06:25 AM
  6. Copy sheets only if condition is satisfied (mat)
    By matthias in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-10-2006, 01:10 PM
  7. Replies: 0
    Last Post: 01-11-2006, 07:31 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