Search code examples
excelvbaexcel-formulaworksheet-function

Matching columns between sheets and transferring names


I'm trying to transfer values with macro in Excel for my upcoming billiards tournament playoff table. For example let's say I have column A with names {A1,A2,A3,A4} and every name is on a different row. Then I have column B in the same sheet with according values {1,4,3,2}. Now I have another sheet which has column I (and previous column H of course) and that column I has values from 1-16. I'd like to match numbers between columns I and B and place names to the previous column (column H).

To visualize this idea (keep in mind that every element is on its own row):

Column A, sheet #1: {A1,A2,A3,A4}   
Column B, sheet #1: {1,4,3,2}    
Column I, sheet #2: {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}   
Column H, sheet #2: {}   

Column H should get values from column A, other rows (which numbers are not in column B) will be left empty.

I've never done VBA before. I know coding in Java and Python but VBA is not really my thing. I'd like to see if anyone could point me in the right direction or maybe should even solve this issue.


Solution

  • I think what you want, is:

    Turn on Record Macro:

    In H1 enter:

    =IFERROR(INDEX('Sheet #1'!A:A,MATCH(I1,'Sheet #1'!B:B,0)),"")
    

    and copy down to suit.