vba 如果返回 #VALUE,则返回空白

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25303568/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 04:14:42  来源:igfitidea点击:

Return blank if #VALUE is returned

excelvbaexcel-vbaformula

提问by Keva161

I've setup a formula that combines numbers from multiple worksheets and then compares it against another number from worksheet.

我已经设置了一个公式,该公式将多个工作表中的数字组合在一起,然后将其与工作表中的另一个数字进行比较。

I am using the INDIRECTfunction to reference the sheets as well as COLUMNand ROWto adjust the numbers to the corresponding coordinates when I drag it across.

我使用的INDIRECT功能来引用片以及COLUMNROW所述数字调整到相应的坐标,当我遇到拖动它。

However, some of the figures don't always exist in the worksheets so a #VALUEerror is returned. How Can I change it so a blank cell is shown if this happens?

但是,有些数字并不总是存在于工作表中,因此#VALUE会返回错误。如果发生这种情况,我该如何更改它以便显示一个空白单元格?

My Current formula: =INDIRECT("'"&$C$11&"'!R"&ROW(E29)&"C"&COLUMN(E29),FALSE)-SUM(INDIRECT("'"&$C$11&"'!R"&ROW(C29)&"C"&COLUMN(C29),FALSE),INDIRECT("'"&$C$13&"'!R"&ROW(E29)&"C"&COLUMN(E29),FALSE))

我目前的公式: =INDIRECT("'"&$C$11&"'!R"&ROW(E29)&"C"&COLUMN(E29),FALSE)-SUM(INDIRECT("'"&$C$11&"'!R"&ROW(C29)&"C"&COLUMN(C29),FALSE),INDIRECT("'"&$C$13&"'!R"&ROW(E29)&"C"&COLUMN(E29),FALSE))

回答by Bathsheba

Use =IFERROR(<your original formula>, "")which will replace any error with ""but passes any other result through.

使用=IFERROR(<your original formula>, "")它将替换任何错误,""但传递任何其他结果。

But do bear in mind the degradation in spreadsheet stability: INDIRECTmakes spreadsheets brittle enough on its own: your hiding any error output could be dangerous.

但是请记住电子表格稳定性的下降:INDIRECT使电子表格本身变得足够脆弱:隐藏任何错误输出可能是危险的。