title: vba paste not working
body: <p>So I have produced this code so far, but I cannot get the paste to work.</p>
  
  <p>The idea is run through 190 workbooks and to paste formulas in some cells with constants in others (range H1:Z160) which grade an excel exam. All the formulas and constants paste and work if done manually.</p>
  
  <p>The paste function (labelled) fails with this error:</p>
  
  <p><a href="https://i.stack.imgur.com/tNLw7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tNLw7.png" alt="error message"></a></p>
  
  <p>This is the now updated and corrected code:</p>
  
  <pre><code>    Option Explicit
  
  Sub Examnew()
      Dim rCell As Range, rRng As Range 'define loop names
      Dim wbmaster As Workbook                     'name for master workbook
      Dim wbtarget As Workbook                      'name for student workbook
     Set wbmaster = ActiveWorkbook               'set the name for the master
     Dim i As Long                                           'a counter for the result pasteback
  
  With Application '&lt;--|turn off screen &amp; alerts only removed while testing
  .ScreenUpdating = False
  .EnableEvents = False
  End With
  
  i = 1   'Set the counter for result paste back
  
      'Student numbers in cells B3:B136 WARNING SET TO 2 STUDENTS ONLY FOR TEST
      'NOTE that st Nums are in col B with a duplicate in col A to collect results.
      Set rRng = wbmaster.Sheets("studentlist").Range("B3:B4")
      ActiveSheet.DisplayPageBreaks = False '&lt;  | turn off page breaks for speed
  
      For Each rCell In rRng '&lt;                 | loop through "students" range
  
           ActiveSheet.DisplayPageBreaks = False '&lt;  | turn off page breaks for speed
  
        'now open Student exam workbook and set to name "wbtarget"
           Workbooks.Open ("/Users/michael/Final_V1/" &amp; rCell.Value &amp; ".xlsx")
           Set wbtarget = Workbooks(rCell.Value &amp; ".xlsx")
  
       'do copy &amp; paste from Master to Target
           wbmaster.Sheets("Answers_Source").Range("h1:z160").Copy
           wbtarget.Sheets("ANSWERS").Range("h1:z160").PasteSpecial
  
           Application.CutCopyMode = False      'Clear the copy command
  
      'Now collect the result in cell I4 and paste it back into column B using the rCell
      'for that student number matches the st num in col A
          wbtarget.Sheets("Answers").Range("I4").Copy
          wbmaster.Sheets("studentlist").Range("B" &amp; 2 + i).PasteSpecial xlPasteValues
  
          Application.CutCopyMode = False      'Clear the copy command
  
       'now save and close the student file...
          wbtarget.Close (True)
  
          i = i + 1      'increment i for next pasteback
  
  
      Next rCell   '&lt;                            | next student number
     'save the results file
     wbmaster.Save
  
  
         ActiveSheet.DisplayPageBreaks = True '&lt;    | turn back on page breaks once all done
  
  'turn screen &amp; alerts back on
  With Application
  .ScreenUpdating = True: .DisplayAlerts = True
  '.DisplayPageBreaks = True
  End With
  End Sub
  </code></pre>
  
  <p>Which works perfectly, Thanks guys.</p>