savindrasingh
Board Regular
- Joined
- Sep 10, 2009
- Messages
- 183
Hello Experts,
Can any one please let me know how to increase the limit of FOR NEXT LOOP upper limit during execution of the loop?
For example:
If I am trying to execute a piece of code on list of items in a column and the number of items in the column are increased during execution based on some condition then the upper limit of the for loop should include these newly added rows:
The FOR NEXT loop is not considering the new value of the TotalItems variable
What can be done for this?
Can any one please let me know how to increase the limit of FOR NEXT LOOP upper limit during execution of the loop?
For example:
If I am trying to execute a piece of code on list of items in a column and the number of items in the column are increased during execution based on some condition then the upper limit of the for loop should include these newly added rows:
Code:
TotalItems = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 to TotalItems
MsgBox Range("A" & i).Value
If Range("A" & i).Value = Range("B" & i).Value Then
Range("A" & i).Offset(1,0).EntireRow.Rows.Insert
TotalItems = TotalItems + 1
End If
Next
The FOR NEXT loop is not considering the new value of the TotalItems variable

What can be done for this?