'Copy rows from multiple workbooks based on cell value

How do I copy cells from a workbook based on a cell-value.

In the excel file that needs to be filled, column B contains a part of a filename in which the data can be found.

B2 contains 312123-145

B3 contains 312123-195

etc, 

normally around 18rows, but the loop/step can go until a empty cell if found

The workbook the data contains is the cell-value.xlsm There is a sheet with name Yield in the 312123-145.xlsm From that sheet I would like to copy A2:N2, and paste that data at the main excel sheet, in columns E:R in the corrosponding row.

I don't know how to start on to look-up a cell value and find the file with the correct data and then how do I step to the next row.

This the code I started with, I hardcoded first all cellvalues to keep it simple.

Sub ImportWorksheet() 
    ' This macro will import a file into this workbook 
    Sheets("Sheet1").Select 
    PathName = "C:\Documents\test\"
    Filename = "312123-195" 
    TabName = "Yield"
    ControlFile = ActiveWorkbook.Name 
    Workbooks.Open Filename:=PathName & Filename 
    ActiveSheet.Name = TabName 
    Sheets(TabName).Copy After:=Workbooks(ControlFile).Sheets(1) 
    Windows(Filename).Activate 
    ActiveWorkbook.Close SaveChanges:=False 
    Windows(ControlFile).Activate 
End Sub


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source