开发者

excel vba: setting the formula to equal A or B if not found A

开发者 https://www.devze.com 2022-12-31 11:07 出处:网络
i have a vba line of code like this: ActiveCell.FormulaR1C1 = \"=LOOKUP(\"\"ETG_C\"\",RC[-10],RC[-8])\"

i have a vba line of code like this:

ActiveCell.FormulaR1C1 = "=LOOKUP(""ETG_C"",RC[-10],RC[-8])"

i would like to know how is it possible to have the activecell formula be something else in the case that it does not find ETG_C

for example:

=if(not(LOOKUP(""ETG_C"",RC[-10],RC[-8]))开发者_如何学Python) then =LOOKUP(""something_else"",RC[-10],RC[-8])


Yes it is possible.

The key is to check first formula for errors with ISERROR(value) formula

this goes like this:

=IF(ISERROR(FIRST_STATEMENT),SECOND_STATEMENT,FIRST_STATEMENT)

so in your case it should be like:

=if(iserror(LOOKUP(""ETG_C"",RC[-10],RC[-8])), LOOKUP(""something_else"",RC[-10],RC[-8]), LOOKUP(""ETG_C"",RC[-10],RC[-8]))
0

精彩评论

暂无评论...
验证码 换一张
取 消