I am trying to make a program which moves ranges of cells, but one of my Do loops isn't working. In particular elements of the column crawling. When the program is run only A7:A9 get filled instead of A7:J9. The crawling does work for the movement of line 1 to L1 and works if there is no value in the red line (if A10 is blank then B7:B9 will fill). What is my mistake?
Sub Columntest()
Dim i As Integer, j As Integer, k As Integer
i = 1
j = 2
k = 7
Do Until i = 11
Range("L1").Formula = Cells(1, i)
If Cells(10, i).Value = "Low" Then
Do Until j = 6
Cells(j + 15, 1).Formula = Cells(j, i)
j = j + 1
Loop
Do Until k = 10
Cells(k + 5, 1).Copy
Cells(k, i).PasteSpecial xlPasteValues
k = k + 1
Loop
End If
If Cells(10, i).Value = "High" Then
Do Until j = 6
Cells(j + 15, 1).Formula = Cells(j, i)
j = j + 1
Loop
Do Until k = 10
Cells(k + 5, 2).Copy
Cells(k, i).PasteSpecial xlPasteValues
k = k + 1
Loop
End If
i = i + 1
Loop
End Sub
J & K Variable should be set to default inside do while loop:
i = 1
Do Until i = 11
j = 2
k = 7
......
......
...... and so son
Because once the J & K reaches to max values after the first loop, it will never enter in the Do While Loop of J & K again until you reset the J & K's values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With