+ Reply to Thread
Results 1 to 15 of 15

IF AND function not working.. maybe Mac issue?

  1. #1
    Registered User
    Join Date
    01-22-2016
    Location
    Houston, TX
    MS-Off Ver
    Mac 2011
    Posts
    6

    IF AND function not working.. maybe Mac issue?

    Hey all!

    Thanks for taking the time to read this. I am pretty good at excel, but this one is stumping me. I think it might ultimately be a compatibility issue, as I run Mac Excel 2011. I have a column (let's say A) of times properly formatted, so 2pm is 14:00:00. In the column next to it (let's say B) I am writing a logic equation to determine if the value in column A is between a certain time... in this case between 10 and 14. If it is, simply say so; otherwise, tell me it's not.

    This is my code:

    =IF(AND(A1>=TIME(10,0,0),A1<=TIME(14,0,0)),"between 10 and 14","not between 10 and 14")

    It always comes up with the null, or "not between 10 and 14". I have back tested simpler logic and it works fine, but for some reason it breaks once I put the range of times in there. Can someone run this in a different version of Excel, or tell me what is broken here?

  2. #2
    Forum Expert sourabhg98's Avatar
    Join Date
    10-22-2014
    Location
    New Delhi, India
    MS-Off Ver
    Excel 2007, 2013
    Posts
    1,899

    Re: IF AND function not working.. maybe Mac issue?

    I have no experience with Mac however this formula works completely perfectly for me.
    Happy to Help

    How to upload excel workbooks at this forum - http://www.excelforum.com/the-water-...his-forum.html

    "I don't get things easily, so please be precise and elaborate"

    If someone's post has helped you, thank by clicking on "Add Reputation" below the post.
    If your query is resolved please mark the thread as "Solved" from the "Thread Tools" above.

    Sourabh

  3. #3
    Registered User
    Join Date
    01-22-2016
    Location
    Houston, TX
    MS-Off Ver
    Mac 2011
    Posts
    6

    Re: IF AND function not working.. maybe Mac issue?

    Thanks so much! I thought I was going crazy but now I'm pretty convinced it's a Mac issue

  4. #4
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: IF AND function not working.. maybe Mac issue?

    Quote Originally Posted by jjthaeler View Post
    =IF(AND(A1>=TIME(10,0,0),A1<=TIME(14,0,0)),"between 10 and 14","not between 10 and 14")
    It always comes up with the null, or "not between 10 and 14".
    Quote Originally Posted by jjthaeler View Post
    I'm pretty convinced it's a Mac issue
    Probably not! What does =ISTEXT(A1) return? My guess: TRUE. The point is: I wonder if the "times" in column are actually text, not numeric time.
    Last edited by joeu2004; 01-22-2016 at 01:25 PM. Reason: typos

  5. #5
    Forum Expert sourabhg98's Avatar
    Join Date
    10-22-2014
    Location
    New Delhi, India
    MS-Off Ver
    Excel 2007, 2013
    Posts
    1,899

    Re: IF AND function not working.. maybe Mac issue?

    But as he said, "times are properly formatted" it should not be a formatting issue...

  6. #6
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: IF AND function not working.. maybe Mac issue?

    Quote Originally Posted by joeu2004 View Post
    Probably not! What does =ISTEXT(A1) return?
    IN addition to that question..

    Is the value in A1 a TIME ONLY value, or does it also have a DATE value?

    Try
    =IF(AND(MOD(A1,1)>=TIME(10,0,0),MOD(A1,1)<=TIME(14,0,0)),"between 10 and 14","not between 10 and 14")

  7. #7
    Registered User
    Join Date
    01-22-2016
    Location
    Houston, TX
    MS-Off Ver
    Mac 2011
    Posts
    6

    Re: IF AND function not working.. maybe Mac issue?

    Ah ha! It indeed returns true. I manually formatted that column to be Time from the dropdown formatting options, but your text test is passing. What, then, is the most assured way to make the formatting time?

  8. #8
    Registered User
    Join Date
    01-22-2016
    Location
    Houston, TX
    MS-Off Ver
    Mac 2011
    Posts
    6

    Re: IF AND function not working.. maybe Mac issue?

    It is just a time value. The value returns TRUE.

  9. #9
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: IF AND function not working.. maybe Mac issue?

    Quote Originally Posted by sourabhg98 View Post
    "times are properly formatted" it should not be a formatting issue...
    Just because a cell is 'Formatted' as a time, does not mean that cell actually 'contains' a real time value.


    @jj

    Try copying a blank cell
    Highlight the column of times
    Right Click - Paste Special - Values - Add - OK

  10. #10
    Registered User
    Join Date
    01-22-2016
    Location
    Houston, TX
    MS-Off Ver
    Mac 2011
    Posts
    6

    Re: IF AND function not working.. maybe Mac issue?

    This worked perfectly... but why the hell would the Excel formatting of Time just be nominal, and not actual? What did I do by following your instructions to change the true formatting to Time?

  11. #11
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: IF AND function not working.. maybe Mac issue?

    The value you had in A1 was just a Text String in Excel's mind (if it has such a thing), it wasn't really a true Time Value.
    It's called a "Number Stored As Text"
    A numeric value that is being treated as a Text String.

    WHY that cell was considered TEXT, I don't know. How did the value originally get into A1 ?

    And changing the format of a cell is really only for appearnces, for your eye's sake.
    It just changes the way values 'appear' in the cell.
    It does not actually change the value contained in the cell.

    An easy way to 'convert' a Number Stored As Text into a Real Number is to simply Add 0 to it
    So you could just do =A1+0
    But that would be a pain to do to all the values in the column.

    The method I showed is a shortcut to do them all at once.

    A blank cell is usually given the numeric value of 0
    So copying a 0, and doing Paste Special - Values - Add
    Adds 0 to the values in the column
    Thus converting them to real numeric values.

  12. #12
    Registered User
    Join Date
    01-22-2016
    Location
    Houston, TX
    MS-Off Ver
    Mac 2011
    Posts
    6

    Re: IF AND function not working.. maybe Mac issue?

    Hmm no idea. I guess in banking we don't deal with dates like this too frequently. For the record, the times were generated with a random function:

    =TEXT(RAND()*(23-10)/24+10/24,"HH:MM:SS ")

  13. #13
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: IF AND function not working.. maybe Mac issue?

    Quote Originally Posted by jjthaeler View Post
    =TEXT(RAND()*(23-10)/24+10/24,"HH:MM:SS ")
    And that's why it was treated as text, because you told it to.
    The TEXT function returns a value as....you guessed it....TEXT.

    Try changing that to
    =TEXT(RAND()*(23-10)/24+10/24,"HH:MM:SS ")+0

    Or remove the text function completely
    =RAND()*(23-10)/24+10/24

    And just format the cell as time (which you did anyway)

  14. #14
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: IF AND function not working.. maybe Mac issue?

    Quote Originally Posted by Jonmo1 View Post
    Try changing that to
    =TEXT(RAND()*(23-10)/24+10/24,"HH:MM:SS ")+0

    Or remove the text function completely
    =RAND()*(23-10)/24+10/24
    An important difference: the latter is not likely to match constant times of the form 12:34:56.

    If that's important to you, use the first form. That's its purpose: to round time to the second.
    Last edited by joeu2004; 01-22-2016 at 01:23 PM. Reason: cosmetic

  15. #15
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: IF AND function not working.. maybe Mac issue?

    Quote Originally Posted by jjthaeler View Post
    the times were generated with a random function:
    =TEXT(RAND()*(23-10)/24+10/24,"HH:MM:SS ")
    More reliable:

    =RANDBETWEEN(10*3600, 23*3600-1) / 86400

    formatted as Custom hh:mm:ss .

    Note that there are 3600 sec in an hour and 86400 sec in a day. Of course, you can use 36000 and 82799 instead.

    And it still would be prudent to write the following, if you intend to compare the result with constant times (e.g. MATCH or VLOOKUP):

    =--TEXT(RANDBETWEEN(36000,82799)/86400, "[h]:m:s")

    --TEXT(...) has the same effect as TEXT(...)+0. It's just a matter of personal preference.

    This is needed to avoid anomalies of arithmetic with the binary representation of time in Excel, which can result in infinitesimal differences from expectations.

    The use of "[h]" instead of "h" is just in case you use this paradigm in the future for times up to or more than 24 hours ("defensive programming").

    I think your intent is to generate random time between 10:00 AM and 10:59:59 PM, accurate to the second.

    Your formula might result in 23:00:00 because Excel rounds fractional seconds when formatting hh:mm:ss.

    (If you want time up to and including 11:00:00 PM, change 82799 to 82800, of course. The RANDBETWEEN formula still seems preferable, IMHO. But again, it's a matter of personal perference.)
    Last edited by joeu2004; 01-22-2016 at 02:18 PM. Reason: typo: 83000->82800

+ 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. Working Hours issue when cascading deadlines
    By ettyenn in forum Excel Formulas & Functions
    Replies: 19
    Last Post: 06-16-2015, 09:28 AM
  2. [SOLVED] MAJOR ISSUE - CommandButtons Not Working
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-11-2014, 12:40 PM
  3. Very strange issue working with internet explorer please help!
    By papasmurfuo9 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-11-2014, 07:49 AM
  4. [SOLVED] Issue with Private sub working with some columns and not others
    By thumperjlp in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-01-2013, 06:54 PM
  5. IF AND Statement issue not working
    By AESP920 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-17-2010, 04:49 PM
  6. Issue while working with images
    By hari_trainer in forum Excel General
    Replies: 1
    Last Post: 07-15-2010, 12:14 PM
  7. Code not working exactly, copy and paste issue
    By jpthelpguy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-22-2009, 01:42 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