D_Marcel
10-22-2015, 11:05 AM
Dears,
Greetings!
I'll not present a problem that I need to solve, but something I realized after using the "For To" loop today.
This is the code originally designed:
Sub Break_List()
Dim Index As Long
Dim Rows_Counter As Long
Rows_Counter = ActiveSheet.UsedRange.Rows.Count
For Index = 70274 To Rows_Counter
Cells(Index, 2).Select
If Cells(Index, 2).Value <> Cells(Index - 1, 2).Value Then
Cells(Index, 2).EntireRow.Insert
Rows_Counter = ActiveSheet.UsedRange.Rows.Count
Index = Index + 1
End If
Next Index
End Sub
Before enter in the loop (For Index...), the value determined to the variable "Rows_Counter" is 70274. However, as new lines is being inserted inside the loop, its value is incremented as long as the code is running. I was expecting that the code will run until the last row, 70585 after all the new lines, but it stops at 70274.
Do someone knows why this happen?
Thanks a lot!
Kind regards,
Douglas Marcel de Moraes
Greetings!
I'll not present a problem that I need to solve, but something I realized after using the "For To" loop today.
This is the code originally designed:
Sub Break_List()
Dim Index As Long
Dim Rows_Counter As Long
Rows_Counter = ActiveSheet.UsedRange.Rows.Count
For Index = 70274 To Rows_Counter
Cells(Index, 2).Select
If Cells(Index, 2).Value <> Cells(Index - 1, 2).Value Then
Cells(Index, 2).EntireRow.Insert
Rows_Counter = ActiveSheet.UsedRange.Rows.Count
Index = Index + 1
End If
Next Index
End Sub
Before enter in the loop (For Index...), the value determined to the variable "Rows_Counter" is 70274. However, as new lines is being inserted inside the loop, its value is incremented as long as the code is running. I was expecting that the code will run until the last row, 70585 after all the new lines, but it stops at 70274.
Do someone knows why this happen?
Thanks a lot!
Kind regards,
Douglas Marcel de Moraes