简体   繁体   中英

Excel If statement to sum if cell contains a certain string

I am trying to code an IF statement to sum based on certain criteria.

I have attached a screen shot for better understanding. Essentially what I want to achieve is this:

  • In my screen shot Cell U4 is the sum of Cell R4:T4
  • I want to incorporate a test so that if Cell O4 contains "yes" then sum and show the number
  • But, if Cell O4 contains "No" then show me the text "fail"

Screen shot below, and as always thank you so much for any help you can give

在此处输入图片说明

=IF(O4="yes",SUM(R4:T4),"fail")

如果您要检查任何潜在的错误或空白,这将fail"yes"以外的每个值都fail 。请使用

=IF(O4="yes",SUM(R4:T4),IF(O4="no","fail","ERROR"))

You could do this with the following formula:

=IF(O4="yes",SUM(R4:T4),"fail")

But that would mean that fail would return for all values that are not yes , not just no .

So alternatively, you could use this formula:

=IF(O4="yes",SUM(R4:T4),IF(O4="no","fail","foo"))

But you need to think about what happens if O4 is neither yes nor no .

HTH.

Hi so I hope this helps someone as this site is amazing for helping Rookies like me out. I wanted a txt response to certain criteria and the formula that works in my example is =IF(O4="No","FAIL",SUM(R4:T4))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM