Iterating with "insertrefplane" using VBA logic statements

Hi everyone,

I was wondering if anyone has had any success iterating the creation of a plane using the "insertrefplane" command while it is embedded in a statement with coding logic (if, for, else, while...)

Every time I try to run a code like this, even if I am only iterating through one loop or trying to make a single plane, Solidworks crashes.

I would welcome any kind of help/suggestions/input involving the insertrefplane function at this point.

Thank you!

SolidworksApi macros