Forum Discussion
tristaanogre
7 years agoEsteemed Contributor
As you delete rows, the row count changes... and the index of each row changes. So, let's say you have a date row at row 5 and another one at row 6. So, you find the one at row 5... you delete it... now the one at row 6 is now row 5. but you've already iterated through row 5 so whatever is in row 5 now gets skipped. So, you are dealing with a grid that is changing length as you are looping through it.
You will probably also get another error where you may try to access a row that no longer exists when you get to the end.
So... instead of a for loop...you're going to need to do something entirely different. You're going to need to do (again, pseudo-code) something like:
var foundRow = Grid.FindRow('Created Date') //I think this code you already know how to use.
while (foundRow != -1) { //Assuming foundRow returns -1 if it doesn't find something
//Do your stuff where you click the cell, delete, etc.
//repeat the findRow
foundRow = Grid.FindRow('Created Date')
}