I'm looping through a selection set in my script and getting 'object expected'. What could be the problem?

Responsive Ad Header

Question

Grade: Education Subject: Support
I'm looping through a selection set in my script and getting 'object expected'. What could be the problem?
Asked by:
106 Viewed 106 Answers

Answer (106)

Best Answer
(357)
The issue is likely that the selection set is changing size during the loop (e.g., entities are being deleted within the loop). This can cause the loop to try to access an object that no longer exists. To avoid this, either create a copy of the selection set before looping, or loop backwards through the selection set (from the last element to the first).