+ Reply to Thread
Results 1 to 13 of 13

excel formula with if

  1. #1
    Forum Contributor
    Join Date
    06-03-2020
    Location
    canada
    MS-Off Ver
    2021
    Posts
    159

    excel formula with if

    Hello
    Trying to write theese 3 conditions with if and i need some help to do it.
    Thanks in advance for any help.


    A2>"06:30" et A2<="14:30";"Jour"
    A2>"14:30" et A2<="22:30";"Soir"
    A2>"22:30" et A2<="06:30";"Nuit"

  2. #2
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.96 for Mac MS 365
    Posts
    8,690

    Re: excel formula with if

    this is doable if you convert the times into numbers. AND, don't put times or numbers into quotes because that changes them to text which doesn't work with greater or less than or equal to.
    I believe this will work for you...
    =IF(AND(A2>0.2708;A2<=0.6042);"Jour";IF(AND(A2>0.6042;A2<=0.9375);"Soir";IF(OR(A2<=0.2708;A2>0.9375);"Nuit";"")))
    Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
    Sam Capricci

  3. #3
    Forum Contributor
    Join Date
    06-03-2020
    Location
    canada
    MS-Off Ver
    2021
    Posts
    159

    Re: excel formula with if

    Hello Sir
    it works, but i have 2 questions for you.

    how to convert the time to number
    when A2 is empty, the formula display "Nuit". How to make it display blank when A2 is nothing?

    Thank you

  4. #4
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.96 for Mac MS 365
    Posts
    8,690

    Re: excel formula with if

    well, for question 1, you don't have to convert your time to numbers, I did it in the formula. If you have times in the cells, times are simple representations of numbers, so noon (12:00) looks like a time in a cell but if you convert from a time to a number it will look like 0.50.

    question 2, change the formula to this instead...
    =IF(A2="";"";IF(AND(A2>0.2708;A2<=0.6042);"Jour";IF(AND(A2>0.6042;A2<=0.9375);"Soir";IF(OR(A2<=0.2708;A2>0.9375);"Nuit"))))

  5. #5
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2019
    Posts
    4,542

    Re: excel formula with if

    Try this formula:=IF(A2="","",IF(OR(MOD(A2,1)>TIME(22,30,1),MOD(A2,1)<=TIME(6,30,1)),"Nuit",IF(MOD(A2,1)>TIME(14,30,1),"Soir","Jour")))
    Last edited by josephteh; 03-27-2022 at 12:07 AM.

  6. #6
    Forum Contributor
    Join Date
    06-03-2020
    Location
    canada
    MS-Off Ver
    2021
    Posts
    159

    Re: excel formula with if

    tha's work.
    thanks a lot!

  7. #7
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2024
    Posts
    6,177

    Re: excel formula with if

    Or try this:

    =IF(A2="","",LOOKUP(A2*86400,{0,23401,52201,81001},{"Nuit","Jour","Soir","Nuit"}))

  8. #8
    Forum Contributor
    Join Date
    06-03-2020
    Location
    canada
    MS-Off Ver
    2021
    Posts
    159

    Re: excel formula with if

    Hello
    As mentionned, your code is working great, but i have another request which is!
    1. if B2 is not empty, do the code
    2. if B2 is empty, switch to A2 value to execute the code.

    For better understanding, i add a screen shot.

    Thanks!
    Attached Images Attached Images

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,968

    Re: excel formula with if

    This is not code, it's a formula.

    Try this:

    =IF(AND(A2="",B2=""),"",LOOKUP(IF(B2<>"",B2,A2)*86400,{0,23401,52201,81001},{"Nuit","Jour","Soir","Nuit"})))

    Semi-colons may be needed for your locale:

    =IF(AND(A2="";B2="");"";LOOKUP(IF(B2<>"";B2;A2)*86400;{0;23401;52201;81001};{"Nuit";"Jour";"Soir";"Nuit"})))
    Last edited by AliGW; 03-27-2022 at 11:30 AM.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  10. #10
    Forum Contributor
    Join Date
    06-03-2020
    Location
    canada
    MS-Off Ver
    2021
    Posts
    159

    Re: excel formula with if

    Hello
    Doesn't work for me. when i erase B2, the formula doesn't take A2 value. insted, the cell shows nuit.

    Thanks!

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,968

    Re: excel formula with if

    Well, it should!

    Attach a sample workbook, then we can see what's happening.

  12. #12
    Forum Contributor
    Join Date
    06-03-2020
    Location
    canada
    MS-Off Ver
    2021
    Posts
    159

    Re: excel formula with if

    Hello
    Really appreciate your help!
    Is working fine now.

  13. #13
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,968

    Re: excel formula with if

    Oh, OK!

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, if you have not already done so, you may not be aware that you can thank those who have helped you by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of all those who offered help.

+ 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. Formula for stock cover/ days in inventory and also generate excel formula for it
    By james brownson in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 07-14-2021, 01:41 AM
  2. [SOLVED] VBA, User-defined formula argument referring to cell value calculated by Excel formula
    By ARAGORN II in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-23-2017, 01:57 PM
  3. Excel formula bar to display the result of the formula , not the formula?
    By max_max in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-18-2016, 07:15 PM
  4. Replies: 10
    Last Post: 12-16-2015, 03:16 PM
  5. Replies: 2
    Last Post: 03-21-2014, 11:43 AM
  6. Replies: 0
    Last Post: 03-19-2012, 07:32 PM
  7. Replies: 1
    Last Post: 03-04-2012, 12:03 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