Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试通过 VBA 代码计算 Excel 表中的百分比,如下所示:
.ActiveCell.FormulaR1C1 = "=IF((ISBLANK(RC[-2])=FALSE),IF((ISERROR(RC[-2]/RC[-1]),0,RC[-2]/RC[-1]),"""")"
但这给了我一个错误。
如果该RC[-2]列为空,则%列的结果应该为空,如果不是,我需要检查分母是否为0以避免除以零错误(#DIV/0! 如果分母为零则填充)
RC[-2]
#DIV/0!
有人可以指出错误在哪里吗?
你错过了一个右括号 - 这可能会更好(不确定它是否会做你想要的!):
"=IF(ISBLANK(RC[-2])=FALSE,IF(ISERROR(RC[-2]/RC[-1]),0,RC[-2]/RC[-1]),"""")"
或者更具可读性:
"=IF(ISBLANK(RC[-2]),"""",IF(ISERROR(RC[-2]/RC[-1]),0,RC[-2]/RC[-1]))"