Forum Discussion
webbk22
Apr 13, 2022Copper Contributor
Cannot get my excel loop to move to the next cycle
I want my Macro to loop every 3rd row. Here is the code I am using. It will run through the code find perform the functions great on the first pass, but on the second pass, the loop moves back to ("...
JMB17
Apr 13, 2022Bronze Contributor
webbk22 It appears that you want to loop through the cells, in blocks of 3, delete the first cell (column A & B, shifting to the left), move the second cell over one column (to B), and move the third cell over six columns (to F)?
If so, you could try this (be sure to back up your data first as you can't undo a vba action):
Sub Module2()
Dim i As Long
Dim rng As Range
Set rng = Range("A1", Range("A1").End(xlDown))
With rng
If .Rows.Count Mod 3 > 0 Then Exit Sub
For i = rng.Rows.Count To 1 Step -3
.Cells(i, 1).Cut .Cells(i, 1)(1, 6)
.Cells(i - 1, 1).Cut .Cells(i - 1, 1)(1, 2)
.Cells(i - 2, 1).Resize(1, 2).Delete shift:=xlToLeft
Next i
End With
End Sub