title: "Object variable or With block variable not set" in VBA
body: <p>I am looking to calculate a column (in wsOut) of averages using VBA. The input is in another sheet (wsRefor).</p>
  
  <p>I use the following code, where I use the worksheet function to calculate the average</p>
  
  <pre><code>Dim Avg As Double
  Dim AvgRange As Range
  Set Reformulering = ActiveSheet
  
  For i = 1 To lastCol
      AvgRange = Range(wsRefor.Cells(1 + i, 4), wsRefor.Cells(1 + i, lastCol))
      wsOut.Cells(i + 1, 4).Value = Application.WorksheetFunction.Average(AvgRange)
  Next
  </code></pre>
  
  <p>Yet, I get the mistake, from the second line inside of the for-loop:</p>
  
  <p>"Object variable or With block variable not set"</p>
  
  <p>I am not sure I understand the error from videos I have watched and other forum discussion, so I am hoping anyone can explain or potentially point of the mistake</p>