title: Excel VBA: How to create loop and save output for each value in range?
body: <p>I'm trying to create a loop in excel, but I'm stuck. </p>
  
  <p>The purpose of my loop is to 
   - Go through a range of values, e.g A1:A8760 and insert it in cell e.g B10
   - For each range of values, I want to save the output and copy it in a new column, e.g C. </p>
  
  <p>I tried to record a macro and create a loop from this. But it just went wrong, </p>
  
  <pre><code>gg = 1
  
     Dim myRange As Range
     Dim i As Long, j As Long
  
     Set myRange = Range("AJ4:AJ8763")
     For i = 1 To myRange.Rows.Count
        For j = 1 To myRange.Columns.Count
          myRange.Cells(i, j).Select
      Selection.Copy
      Range("D10").Select
      ActiveSheet.Paste
      Range("O7").Select
      Application.CutCopyMode = False
      Selection.Copy
    myRange.Cells(i, j + gg).Select
      Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
          :=False, Transpose:=False
        Next j
     Next i
  End Sub
  </code></pre>
  
  <p>The code sample above is what I have added so far. So the idea is I go through a range of value from AJ4 to AJ8763 and insert it in cell D10, 
  Next step is to copy the output from cell O7 and insert it to cell AK4 to AK8763.</p>
  
  <p><strong>Added corrected version</strong></p>