title: Copy data Using Vba, Match function
body: <p>i am a new coder.
  Just a beginner in vba, and would like some help to solve this.
  i know i can use normal excel formulas but this is for learning.
  here is my code so far:</p>
  
  <pre><code>Sub matchpart()
  Dim ocell As Range
  Dim swb As Workbook
  Dim sws As Worksheet, dws As Worksheet
  Dim stext As String
  Dim iRow As Long
  Dim nxtRow As Long
  
  
  Set swb = ActiveWorkbook
  Set sws = swb.Sheets("sheet1")
  Set dws = swb.Sheets("sheet2")
  
  For Each ocell In dws.Range("FILE_NAMES")
      stext = Left(ocell.Value, 12)
  On Error Resume Next
  iRow = Application.WorksheetFunction.Match(stext, sws.Range("ID_NUMBER"), 0)
  On Error GoTo 0
      If iRow &gt; 0 Then
         Application.Index (Range("ID_PARENT").Copy)
      Else
          ocell.Offset(0, 1) = ""
          End If
          Next
  
  MsgBox ("Done")
  End Sub
  </code></pre>
  
  <p>my task is to match 1 column from sheet 2 (ID_NUMBER) with 1 column sheet 1 (FILE_NAMES). after this copy the corresponding value in the next column in sheet 1 (which has been matched) and paste it into the next column in sheet 2.</p>
  
  <p>here is my data as an e.g
  sheet1:</p>
  
  <pre><code>ID_PARENT     ID_NUMBER 
  pan               3
  same              2
  kappa             1
  lame              5
  dame              5
  
  sheet 2:
  
  FILE_NAMES      BPM_LIST
  1                   
  5
  3
  2
  4
  5
  </code></pre>
  
  <p>thus would like to match and copy in to BPM_LIST using my code.</p>