Search code examples
excelexcel-formulaxlsxworksheet-functionworksheet

Searching for value and returning another in Excel


I have an excel sheet that has values in two cell (A1 & A2). Cell B1 has either values of them and I want C1 to return the other value in column A.

I tried HLOOKUP but it only works if B1 has the value in A1. I need it to work both ways.

Thank you for your help and time.


Solution

  • In C1 enter:

    =IF(B1=A1,A2,A1)
    

    This should choose the opposite.

    EDIT#1:

    Test for blank first:

    =IF(B1="","",IF(B1=A1,A2,A1))