Ask Your Question
1

Can items be safely removed from a dictionary while iterating through it using a for-each loop in VBA?

asked 2023-02-24 11:00:00 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-10-25 13:00:00 +0000

woof gravatar image

No, items should not be removed from a dictionary while iterating through it using a for-each loop in VBA as it can cause the loop to skip or miss elements, or even throw an error. It is recommended to create a new collection of the items to remove and then remove them outside of the loop. Alternatively, you can loop through the values in reverse order and delete the items as necessary.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-02-24 11:00:00 +0000

Seen: 12 times

Last updated: Oct 25 '21