tags:

views:

83

answers:

1

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]))) then =LOOKUP(""something_else"",RC[-10],RC[-8])
+2  A: 

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]))
Cornelius