Loop to last row while adding rows
问题 My loop is breaking a few thousand lines before the last row. Let's say last row is up to 12000, its looping until 9800. For i = 2 To lastrow If ws.Cells(i, 2).Value = "4" Then Rows(i).Insert Range("E" & i).Value = ws.Cells(i + 1, 5) i = i + 1 lastrow = lastrow + 1 End If Next i 回答1: @Nathan_Sav makes a good point. I'm not sure how the i = i + 1 and Next i interact with each other. I'd try it this way: i = 2 While i <= lastrow If ws.Cells(i, 2).Value = "4" Then Rows(i).Insert Range("E" & i)