For Each may not be used on array of user-defined type or fixed-length strings

For Each constructs are only valid for collections and arrays of intrinsic types, including arrays of objects. Also, arrays of fixed-length strings can't be iterated using For Each. This error has the following causes and solutions:

  • The elements of the array in your For Each construct have a user-defined type.

    Use an ordinary For...Next loop to iterate the elements of the array.

  • The elements of the array in your For Each construct have a fixed-length string type. Use an ordinary For...Next loop to iterate the elements of the array.

For additional information, select the item in question and press F1 (in Windows) or HELP (on the Macintosh).

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.