title: Excel Macro Copy cell range & paste data one sheet to another
body: <p>I am trying to look up a value given a list and copy the remaining row contents into the columns adjacent to the list. I copied some code from this site and have looked for answers elsewhere can't find anything. Every time I run the code it gives me a compile error "Invalid outside procedure"</p>
  
  <pre><code>Sub test()
  Dim LR As Long
  Dim i As Long
  Dim x As Long
  Dim lastDataRow As Long
  Dim lastListRow As Long
  Dim sheetOne As String
  Dim sheetTwo As String
  
  Dim listItem As String
  Dim dataItem As String
  
  Dim listColNum As Long
  Dim dataColNum As Long
  
  listColNum = 1
  dataColNum = 2
  sheetOne = "new_copy"
  sheetTwo = "Historical_data_"
  
  lastListRow = Sheets(sheetOne).Cells(Sheets(sheetOne).Rows.Count, listColNum).End(xlUp).row
  lastDataRow = Sheets(sheetTwo).Cells(Sheets(sheetTwo).Rows.Count, dataColNum).End(xlUp).row
  
  For x = 1 To lastListRow
  
      For i = 1 To lastDataRow
  
          If Sheets(sheetOne).Cells(x, listColNum).Value = Sheets(sheetTwo).Cells(i, dataColNum).Value Then
              Sheets(sheetOne).Cells(x, 3).Value = Sheets(sheetTwo).Cells(i, 3).Value
          End If
  
      Next i
  Next x
  End Sub
  </code></pre>
  
  <p>Any help would be appreciated!</p>