+ Reply to Thread
Results 1 to 23 of 23

Excel 2007 : If statement help

  1. #1
    Registered User
    Join Date
    08-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    34

    If statement help

    I am trying to write an if statement to check 4 numbers to see if they are greater than or equal to each other.

    A. B. C. D
    11 22. 10. 15
    27. 50. 40. 50

    So far I got if(and(a1>=d1,b1>=d1),"red",if(or(a1>=c1,b1>=c1,((b1-a1)*a1))

    But when I copy the code to the second line, I need it to say red but the calculations still shows up since b1>=c1.

    Can anyone help me please
    Last edited by Batman11692003; 08-26-2011 at 01:24 PM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: If statement help

    Did you mean?

    =IF(AND(A1>=D1,B1>=D1),"red",IF(OR(A1>=C1,B1>=C1),(B1-A1)*A1))

    how is second supposed to be "red"? Should you have an OR instead of an AND>
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    08-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: If statement help

    I would like the second row to be red since it meets the first agrument of b2>=d2

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: If statement help

    So then you want OR, not AND...

    Try:

    =IF(OR(A1>=D1,B1>=D1),"red",IF(OR(A1>=C1,B1>=C1),(B1-A1)*A1))

  5. #5
    Registered User
    Join Date
    08-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: If statement help

    Sorry but I forgot to add, for the same example, if a1>=c1 or b2>=c1 I want it to perform the calculation b1-a1*a1. But if at any point like b2>=d2 then I want the code to say red. Thanks

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: If statement help

    Do you mean?

    =IF(OR(A1>=D1,B1>=D1,B2>=D2),"red",IF(OR(A1>=C1,B1>=C1),(B1-A1)*A1))

  7. #7
    Registered User
    Join Date
    08-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: If statement help

    But I also what to calculate/show the value if a1>=c1. But I don't want to see it when b2>=d2

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: If statement help

    Don't know what you mean... did you try the formula.

    If B2>=D2, it will be "red", and if B2<D2 and A1>=C1, you will get a value.

    If you disagree or have issues, post a sample workbook with various samples and expected results, and re-state the full conditions from scratch in words.

  9. #9
    Registered User
    Join Date
    08-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: If statement help

    Here is an excel file to show you want I am trying to do
    Attached Files Attached Files

  10. #10
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: If statement help

    Try:

    =IF(OR(A2>=D2,B2>=D2),"red",IF(OR(A2>=C2,B2>=C2),(B2-A2)*A2))

  11. #11
    Registered User
    Join Date
    08-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: If statement help

    It works for row 2 but it shows up red for the first line. But I want te calculations to show. Since If the box color is yellow and red, or just yellow I want the calculation to show up still.

  12. #12
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: If statement help

    You can't calculate based on cell colours... only cell contents.

  13. #13
    Registered User
    Join Date
    08-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: If statement help

    I just did that to show you want I am looking for. Also when I change it to and for the first if statement and or for the second if statement. The calculations shows for the first row but then it doesn't say red for the second row

  14. #14
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: If statement help

    You know this should be very simple, yet I am having a hard time understanding your requirements or we fell onto different pages at some point.

    Can we start at the beginning and just try articulating your requirements in words.

  15. #15
    Registered User
    Join Date
    08-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: If statement help

    I am trying to find the total of how much I need from stock or the warehouse. So if number sold is greater than stock or peak sold is greater than stock. I would for excel to run the calculation

    But if number sold is greater than or equal to warehouse or if peak sold is greater than or equal to warehouse I just want it to say red

    But if # sold or peak sold is greater than or equal to stock I want the calculation to show up. But if it's on the same line like the B2 in te excel file where there is a red and yellow. I still want the calculations to show up.

    I hope I explained it clear enough for you and thanks for your help already

  16. #16
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: If statement help

    This is the part that is eluding me.

    But if it's on the same line like the B2 in te excel file where there is a red and yellow. I still want the calculations to show up.
    You can't compare colours, so what makes row 2 calculate an answer, and row 3 to return "Red", ignoring the cell colouring?

  17. #17
    Registered User
    Join Date
    08-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: If statement help

    For row 2 since # sold is higher than stock I would like to do the calculation to find how much more I need. And for row 3, since peak sold is greater than or equal to warehouse I would like the if statement to say red when that occurs.

    But let's say if there was a new row added,
    A. B C. D
    49 60 48. 62

    Now a1>=c1 and b1>=c1 so I would want the calculation to show for that new row

  18. #18
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: If statement help

    Is this any closer?

    =IF(A2>=C2,(B2-A2)*A2,IF(OR(A2>=D2,B2>=D2),"red",IF(B2>=C2,(B2-A2)*A2,"")))

  19. #19
    Registered User
    Join Date
    08-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: If statement help

    Thank you. It seems like it's working, but I have to play around with it a little more. Since some columns have Out, so when I run the if statement it says #value!

  20. #20
    Registered User
    Join Date
    08-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: If statement help

    Also what if a and b are both true
    For example
    A. B. C. D
    49. 60. 48. 61

    I tried to add an AND Statement at the end if the last if statement but it still didn't work.

  21. #21
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: If statement help

    Don't know what that means.

  22. #22
    Registered User
    Join Date
    08-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: If statement help

    Sorry. I figured it out. But my question is how do I sum up the values only in the column. Since some say RED and some have #value!.

  23. #23
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: If statement help

    Try:

    =SUMIF(E2:E6,"<="&9.99999999E+307)

    adjusting range to suit.

+ 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