Search code examples
excelexcel-formulaexcel-2010excel-2007

nested if and statement in excel


Good Day

I have a excel sheet that has data for 2014, 2015, 2016 and 2017 I have to fill the 2016 data such that it doesnt contain error messages which is #NUM! statement.

so if I have a table like this

 2014 2015 2016 2017
 23    25  #NUM!  45
 12   #NUM!#NUM!  65
 #NUM #NUM #NUM   70

I need to fill in 2016 such that if it has an error message then take values from 2015, if 2015 has an error message then take values from 2014, if 2016 to 2014 has error values then take values from 2017

This is my current formula but it looks okay but isnt working is there a way around this?

=IF(D2="#NUM!",C2,IF(AND(D2="NUM#!",C2="#NUM!"),B2,IF(AND(D2="#NUM!",C2="#NUM!",B2="#NUM!"),E2,D2)))

this is assuming the 2016 column =D2, 2015=C2, 2014=B2 and 2017=E2

thanks in advance


Solution

  • Use this formula:

    =IFERROR(INDEX(B2:D2,MATCH(1E+99,B2:D2)),E2)
    

    It returns the last actual number in the range, if none are found it errors and the value from 2017 is returned.

    enter image description here