title: VBA Excel User input lookup data different workbook
body: <p>I am on a very basic level of programming, however, as I am the "skilled" one in my company, I turn to you guys for support, I hope you can help me!</p>
  
  <p>My task at hand is as follows.</p>
  
  <p>I have a working workbook, where all the data entries are done and then I have a database file, also excel.</p>
  
  <p>User file: Random name, as the sheet will change depending on the calculation done by the user. Sheet name "Sagsnr." (Caseno. in local language) </p>
  
  <p>Sourcefile: "Matcost.xls", worksheet: "Matcost"</p>
  
  <p>I need to be able to enter a value e.g. a material number or a range of numbers (So range is dynamic) into the active sheet, which will then start looking up specific field of data related to the ID (Mat. number) in the database file.</p>
  
  <p>I will need to have calculation field in between the various data fetched from the database, so I cannot just copy an entire row, but need to fetch for each ID number a set of values from cells in the database to the user input file.</p>
  
  <p>I would like to only fetch the values and not paste a vlookup function into the sheet as this is both "dangerous from a user manipulation point of view as well as making the sheet slow in my experience.</p>
  
  <p>I have now struggled with the above for quite some time and I have tried to lookup various questions and answers on this site as well, but to no apparent working solution. This might be due to my lack of understanding, but I hope you can then either point me to the right answer or answer it here.</p>
  
  <pre><code>Private Sub Worksheet_Change(ByVal Target As Range)
  
  Dim material As String
  Dim fndEntry As Range
  Dim wb1 As Workbook, wb2 As Workbook
  
  Set wb1 = ActiveWorkbook
  
  material = wb1.ActiveCell.Value
  
  ' Find the corresponding value in the Database file
  
  Workbooks.Open Filename:="G:\Backoffice\Tilbudsteam\Kostdatabase\Matcost.xls", ReadOnly:=True
  
  Set wb2 = ActiveWorkbook
  
  'Change the below Range address..
  Set fndEntry = wb2.Range("C:C").Find(What:=material)
  
  'Change the below Range address..
  If Not fndEntry Is Nothing Then
      wb2.Range("B" &amp; fndEntry.Row).Copy Destination:=wb1.ActiveCell.Offset(0, 1)
  End If
  
  
  End Sub
  </code></pre>
  
  <p>Thank you very much in advance!</p>
  
  <p><a href="http://i.stack.imgur.com/wZnnw.jpg" rel="nofollow">User input sheet</a></p>