+ Reply to Thread
Results 1 to 11 of 11

Another if then statement

Hybrid View

  1. #1
    Forum Contributor jonvanwyk's Avatar
    Join Date
    06-28-2010
    Location
    Iowa, USA
    MS-Off Ver
    Excel 2010
    Posts
    452

    Another if then statement

    =IF(OR(C5="V1",C5="V2",C5="V3"),B6-B5,B6)
    In the above code, B5 is "7:00" while B6 is "11:00". Since "V1" was selected for C5, it should subtract 7:00 from 11:00 and return a value of 4 (hours). If V1 had not been selected, it should just display 11:00 (the value of B6).
    Last edited by jonvanwyk; 12-12-2010 at 02:51 PM.

  2. #2
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Another if then statement

    Yes, that is how that formula should work (IF cell C5 is either V1, V2 or V3, then subtract B5 from B6, otherwise enter B6). So what is happening?
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Contributor jonvanwyk's Avatar
    Join Date
    06-28-2010
    Location
    Iowa, USA
    MS-Off Ver
    Excel 2010
    Posts
    452

    Re: Another if then statement

    Quote Originally Posted by ChemistB View Post
    Yes, that is how that formula should work (IF cell C5 is either V1, V2 or V3, then subtract B5 from B6, otherwise enter B6). So what is happening?
    Well, I just realized it is doing the math correctly, but it is converting my "4" into 4:00. I have a different spread sheet where I have a similar equation, and when the result is time, it shows time, and when the result is a integer, it shows the integer.

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Another if then statement

    what is your question? that works fine
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  5. #5
    Registered User
    Join Date
    10-05-2010
    Location
    S.A
    MS-Off Ver
    Excel 2007
    Posts
    99

    Re: Another if then statement

    hi Jonva
    try this code:
    =IF(OR(C5="V1",C5="V2",C5="V3"),(B6-B5+(B6<B5))*24,B6)
    then change the format of your cell to general
    regards,

  6. #6
    Forum Contributor jonvanwyk's Avatar
    Join Date
    06-28-2010
    Location
    Iowa, USA
    MS-Off Ver
    Excel 2010
    Posts
    452

    Re: Another if then statement

    Quote Originally Posted by noexcel=badwork View Post
    hi Jonva
    try this code:
    =IF(OR(C5="V1",C5="V2",C5="V3"),(B6-B5+(B6<B5))*24,B6)
    then change the format of your cell to general
    regards,
    That formula successfully converts the 4:00 into an integer of 4. However, when C5 does not equal V1, V2, or V3, it should show what is in B6, which is 11:00. Now it displays 11:00 as 0.4583333 when I change the format of the cell to general. If I leave it as time, then my integer of 4 changes to 0:00.

  7. #7
    Registered User
    Join Date
    10-05-2010
    Location
    S.A
    MS-Off Ver
    Excel 2007
    Posts
    99

    Re: Another if then statement

    here is the code:
    =IF(OR(C5="V1",C5="V2",C5="V3"),(B6-B5+(B6<B5))*24,B6*24)

  8. #8
    Forum Contributor jonvanwyk's Avatar
    Join Date
    06-28-2010
    Location
    Iowa, USA
    MS-Off Ver
    Excel 2010
    Posts
    452

    Re: Another if then statement

    Quote Originally Posted by noexcel=badwork View Post
    here is the code:
    =IF(OR(C5="V1",C5="V2",C5="V3"),(B6-B5+(B6<B5))*24,B6*24)
    Using this formula, I get a result of "11" instead of "11:00" when format is set to General. When I change the format to [=0]"";hh:mm I get a result of 00:00

  9. #9
    Registered User
    Join Date
    10-05-2010
    Location
    S.A
    MS-Off Ver
    Excel 2007
    Posts
    99

    Re: Another if then statement

    this is the code
    I think this one will work:
    =IF(OR(C5="V1",C5="V2",C5="V3"),(B6-B5+(B6<B5))*24,B6*24&":"&"00")

  10. #10
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Another if then statement

    depends ,do you want to use the 11:00 in other calculations? you cant have 2 formats in the same cell
    similar to above
    =IF(OR(C5="V1",C5="V2",C5="V3"),(B6-B5+(B6<B5))*24,TEXT(B6,"hh:mm")) format general

  11. #11
    Forum Contributor jonvanwyk's Avatar
    Join Date
    06-28-2010
    Location
    Iowa, USA
    MS-Off Ver
    Excel 2010
    Posts
    452

    Re: Another if then statement

    Quote Originally Posted by martindwilson View Post
    depends ,do you want to use the 11:00 in other calculations? you cant have 2 formats in the same cell
    similar to above
    =IF(OR(C5="V1",C5="V2",C5="V3"),(B6-B5+(B6<B5))*24,TEXT(B6,"hh:mm")) format general
    This worked :-) Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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