hi all,
I'm just learning about User Defined Types (UDT's) and am trying to code to allow "flexible"/dynamic looping through a UDT to clear the values (no matter how many elements (terminology?) exist). 1) Is this possible?
2) Or should I learn some more & use a Class approach?
I have 6 UDT's in my code that I'm using to hold values which are pulled from text files & temporarily held in memory before being written to a spreadsheet in one go as an array.
As well as clearing the values, there may be times when I want to limit which "elements" of the Type are written to the spreadsheet. I am hoping to do this by commenting out the element in the Type declaration at the top of the module without having to make further changes within in the code. The way I thought I would be able to do this, was to use a "For each" or "For i = lbound(type) to ubound(type)" but I haven't been able to make it work. I was still hopeful until I found the below info...
Another page in the Help files reinforces this by stating:Excel 2007 Help Files:
The For...Each...Next statement syntax has these parts:
For Each element In group
[statements]
[Exit For]
[statements]
Next [element]
element Required. Variable used to iterate through the elements of the collection or array. For collections, element can only be a Variant variable, a generic object variable, or any specific object variable. For arrays, element can only be a Variant variable.
group Required. Name of an object collection or array (except an array of user-defined types).
statements Optional. One or more statements that are executed on each item in group.
Here's what I've tried so far...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.
Thanks in advancePlease Login or Register to view this content.
Rob
Bookmarks