title: runtime error 1004. method range of object worksheet failed
body: <p>I'm getting a </p>
  
  <blockquote>
    <p>run-time error '1004': method 'range'of object'_worksheet'failed</p>
  </blockquote>
  
  <p>I'm assuming it is the line where it is </p>
  
  <pre><code>Set datarng = purchfcst.Range("A2:Q" &amp; datalastrow)
  </code></pre>
  
  <p>I'm unsure as what the error as I can't see an error with this</p>
  
  <pre><code>Sub updatepacksizecostandorders()
  
  Dim cofws As Worksheet, purchfcst As Worksheet
  Dim coflastrow As Long, purchlastrow As Long
  Dim datarng As Range
  
  
  Set cofws = ThisWorkbook.Worksheets("COF Replen")
  Set purchfcst = ThisWorkbook.Worksheets("purchase forecast")
  
  coflastrow = cofws.Range("G" &amp; Rows.Count).End(xlUp).Row
  purchlastrow = purchfcst.Range("A" &amp; Rows.Count).End(xlUp).Row
  
  Set datarng = purchfcst.Range("A2:Q" &amp; datalastrow)
  
  For x = 2 To coflastrow
      On Error Resume Next
      cofws.Range("G" &amp; x).Value = Application.WorksheetFunction.VLookup(cofws.Range("A" &amp; x).Value.datarng, 2, False)
  
  
  Next x
  
  
  End Sub
  </code></pre>