简体   繁体   English

如何使用嵌套的 IF 和 OR 函数来求解这个方程?

[英]How can I use nested IF and OR functions to solve this equation?

I am trying to get cell A19 to calculate the formula shown below if either cell SHARES LOG I2 or SPREADS LOG F2 have data within.如果单元格SHARES LOG I2SPREADS LOG F2中有数据,我试图让单元格A19计算下面显示的公式。 If there is no data in either of these cells I would like A19 to return a blank cell.如果这两个单元格中没有数据,我希望A19返回一个空白单元格。

Currently, the formula is calculating the formula correctly if one or both of the previously mentioned cells have data within, however, if there is no data in either cell SHARES LOG I2 or SPREADS LOG F2 , cell A19 does not return a blank.目前,如果前面提到的一个或两个单元格中有数据,则公式计算公式正确,但是,如果单元格SHARES LOG I2SPREADS LOG F2中没有数据,则单元格A19不会返回空白。

I cannot figure out why this is as the formula appears correct.我无法弄清楚为什么这是因为公式看起来是正确的。

When there is no data in either SHARES LOG I2 or SPREADS LOG F2 the result in cell A19 is + £ 0.00 / + £ 0.00SHARES LOG I2SPREADS LOG F2中没有数据时,单元格A19中的结果为+ £ 0.00 / + £ 0.00

This is the current formula in cell A19 :这是单元格A19中的当前公式:

=IF(OR(COUNT('SHARES LOG',I2=1),('SPREADS LOG':F2=1)),TEXT(SUM('SHARES LOG':N,N,'SPREADS LOG'.M:M)," + £ #:##0,00")&" / "&TEXT(SUM('SHARES LOG',LL,'SPREADS LOG'!K:K)," + £ #,##0.00"),"")

The correct formula should be:正确的公式应该是:

=IF(OR(COUNT('SHARES LOG'!I2)=1,count('SPREADS LOG'!F2)=1),TEXT(SUM('SHARES LOG'!N:N,'SPREADS LOG'!M:M)," + £ #,##0.00")&" / "&TEXT(SUM('SHARES LOG'!L:L,'SPREADS LOG'!K:K)," + £ #,##0.00"),"")

You have put the '=1' inside the Count so that it compares the cell 'SHARES LOG',I2 or 'SPREADS LOG'.F2 to 1, then counts the result, The result can only be True or False.您已将 '=1' 放在 Count 中,以便它将单元格 'SHARES LOG'、I2 或 'SPREADS LOG'.F2 与 1 进行比较,然后计算结果,结果只能是 True 或 False。 and Count will treat either of these as a number so you will always get a count of 1, meaning that your Or statement will always be satisfied and you will get a formatted number instead of a blank from the If statement.和 Count 会将其中任何一个视为数字,因此您将始终得到 1 的计数,这意味着您的 Or 语句将始终得到满足,并且您将从 If 语句中获得格式化的数字而不是空白。

There are other more direct ways of testing the contents of 'SHARES LOG'.I2 and 'SPREADS LOG'!F2 like using Isnumber (assuming they should contain a number).还有其他更直接的方法可以测试 'SHARES LOG'.I2 和 'SPREADS LOG'!F2 的内容,例如使用 Isnumber(假设它们应该包含一个数字)。

Although an answer already is given by Tom Sharpe , I believe a better solution is formula auditing, explained in this URL .尽管Tom Sharpe已经给出了答案,但我相信更好的解决方案是公式审核,在此 URL中进行了解释。 More exactly, the "Evaluate Formula" feature is exactly what you need to solve this kind of problems: it allows you to evaluate your formula, step by step.更准确地说,“评估公式”功能正是您解决此类问题所需要的:它允许您逐步评估您的公式。 So, you write your formula, and you try to predict what the outcome of the next step will be.因此,您编写公式,并尝试预测下一步的结果。 At the moment your expectations don't match with the result, you have found the error in your formula.在您的期望与结果不匹配的那一刻,您在公式中发现了错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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