Frage

Say I have two Sheets 1 & 2.

Sheet 1 has Column A: Apt No; Column B: House No; Column C: Key No
Sheet 2 has Column A: Apt No; Column B: House No; Column C: Key No

I want to do a vlookup for Sheet 1 – Column C: Key No. Whenever I enter an Apt No or House No in Sheet 1 then Key No shows up on Sheet 1 from Info in Sheet 2. My formula for Column C: Key No of Sheet 1 is

=IFERROR(VLOOKUP(A2,Sheet2!$A$2:$C$5,3,FALSE),"")

How do I get it reference B2 as well?

War es hilfreich?

Lösung 2

As follow up from comments to Q, this one works:

=IFERROR(VLOOKUP(A2,Sheet2!$A$2:$C$5,3,FALSE),
          IFERROR(VLOOKUP(B2,Sheet2!$B$2:$C‌​‌​$5,2,FALSE),""))

Andere Tipps

You can double nest the IFERROR.

=IFERROR(IFERROR(VLOOKUP(A2,Sheet2!$A$2:$C$5,3,FALSE),VLOOKUP(B2,Sheet2!$A$2:$C$5,3,FALSE))),"")

Checks value of A2, if that errors, checks B2, and if that errors returns an error to the upper iferror, which returns the "".

edit *opps I see someone else already suggested this. Apologies.

It may make more sense for you to use a =concatenate function to combine your first and second column into a new column. You would then use this column as your lookup criteria, since chances are, no (or not many of) records in your sheet will have identical apartment numbers AND houce numbers.

This would look something like:

=VLOOKUP([new concatenated column],Sheet2!$A$2:$C$5,3,FALSE)

Hope this helps, if I missed the mark please let me know and I can try my best to elaborate.

The logic is:

  • Put in value for Apt No (in Sheet1) and use VLOOKUP to find Key No (from Sheet2)

    OR

  • If Apt No not available as input, put in House No (in Sheet1) and use VLOOKUP to find Key No (from Sheet2)



On Sheet1.Range("C2") paste in this code:

    =IFERROR(VLOOKUP(A2,Sheet2!$A$2:$C$5,3,FALSE),"")

On Sheet1.Range("D2") paste in this code:

    =IFERROR((IF(C2="", VLOOKUP(B2,Sheet2!$B$2:$C$5,2,FALSE),"")),"")


Once pasted into the cells, copy and drag to fill in formulas for the two columns.


Sheet1 Sheet2



UPDATE:

If you want to just do it where only three columns are visible in Sheet1, I would just insert a new column called Key No and paste in the following code for Range("C2"):

=IF(D2<>"", D2, E2)

This is just saying if D2 is not an empty string, use it as the value. Otherwise, use E2.

Now, if you just want three columns visible on Sheet1, right click and hide columns D and E.

Sheet1

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top