I'm trying to create a loop in excel, but I'm stuck.
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.
I tried to record a macro and create a loop from this. But it just went wrong,
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
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.
Added corrected version