Search code examples
vbaexcelexcel-2007

VLookUp between 2 sheets


I have 2 sheets, they both have sales order, so I have to do a VLookUp, since the salesorders are placed differently in sheet2 than in sheet 1.

I know I have to do a VLookUp, but I don't know how to do it.


Solution

  • In a VLOOKUP function you need to provide the column_num of the value to return. In your case, you can use a MATCH function to find the correct column using the headers.

    In Sheet1!B2, use this formula,

    =IFERROR(VLOOKUP(--RIGHT($A2, 9), Sheet2!$A:$N, MATCH(B$1, Sheet2!$1:$1, 0), FALSE), IFERROR(VLOOKUP(RIGHT($A2, 9), Sheet2!$A:$N, MATCH(B$1, Sheet2!$1:$1, 0), FALSE), ""))
    

    It is unclear on whether the values in Sheet2!A:A are text-that-look-like-numbers or actual numbers. The above will look at both. If your system using a semi-colon as a list separator instead of a comma then that would be,

    =IFERROR(VLOOKUP(--RIGHT($A2; 9); Sheet2!$A:$N; MATCH(B$1; Sheet2!$1:$1; 0); FALSE); IFERROR(VLOOKUP(RIGHT($A2; 9); Sheet2!$A:$N; MATCH(B$1; Sheet2!$1:$1; 0); FALSE); ""))
    

    Fill this both right and down. Each formula will try and match the header label in Sheet1 with a header label in Sheet2 in order to return the correct value.

    The RIGHT function will strip off the S- from the Sagsnr values in Sheet1.

    The IFERROR function will check for a true number and then as text-that-looks-like-a-number. If neither can be matched, it simply returns a zero-length string (e.g. "").

        VLOOKUP with MATCH for column_num