First of all thanks for taking the time to answer me.

@chrisW67: Yes true, the logic was wrong, even correcting it deleting row by row is very slow.

@anda_skoa: I manage to speed things up using the removeRows(), thanks for the idea.