I'm trying to loop through rows from 310 to end of the sheet (thousands of rows), and when cell in f column is empty i want to go trough rows that are two rows under the empty cell until the value of b column is not 2. If in these rows value of r is 100 i want to move the row below the initial row that started the for loop.
When trying to run it excel gives an compiling error: Loop without Do.
This is the first VBA script i have ever written. Familiar to other programming languages like python and java.
Sub moveConditionedRows()
Dim i As Long, j As Long, k As Long, l As Long
For i = 310 To Range("F" & Rows.Count).End(xlUp).Row
If Cells(i, "F").Value = "" Then
i = i + 2
j = i - 1
Do While Cells(i, "B").Value = "2"
k = k + 1
If Cells(i, "B").Value = Cells(j, "C") Then
If Cells(i, "R").Value = "100" Then
Rows(i).Cut
Rows(i - k).Insert
End If
Loop
End If
Next i
End Sub
Aucun commentaire:
Enregistrer un commentaire