Excel VBA: custom collection duplicated items -


I have created a class that contains a custom collection class when the parent class is filled from the item when the parent class is started. The problem is that when I repeat through the objects of the collection, the properties of the last item are added in all the items. Items must be added to cells in ActiveSheet, each item has a name and range properties, the name is the value of the cell, the range range is. So in cell A1: D1, I have the value ID, Q1, Q2, Q3 and when I make an example of the parent class, then I hope the members of the collection are named id, Q1, Q2, Q3 and range A1, B1 will be C1. , D1 When I repeat, the output shows Q3, Q3, Q3, Q3 and $ D $ 1, $ D $ 1, $ D $ 1, $ D $ 1.

Where's the problem?

Code below:

  Sub test (sample sample) as sample sample = new sample dim field in sample as new field for each FLD . Filters Debug Print fld.Name; VbTab; Fld.Range.Address Next End sub  

field class:

  Get the string public property name as a private category name in the form of a private category ( ) As the string name = PName end property public property name (value as string) pName = value end property public property set range (range as rng) field class (custom collection):  
  private pstfile_size private sub-class as collection Set (Set) pFields = New archive ending sub-sub-square-guitar () Set pFields = None End sub folk function NewEnum () as set as IUnknown NewEnum = pFields. [_NewEnum] Termination Function Add Public Sub (field as field) pFields.Add fld termination deputy folk sub (index as diversity) pFields.End End End Sub Public property item (as in the form of index) Field set items = pFields.Item (index) end property property as GE calculate () long term = pFields.Count termination property public sub clear (set) pFields = new archive ending sub  

More sample Class (with a field collection class):

"A1"). CurrentRegion.Rows (1) in rngHeaders for each RNGGL. New field as new field new field new field.Name = rngCell.Value2 set NewField .Range = rngCell pFields.Add NewField Next rngCell End Sub

The problem is resolved.

has changed this:

  rngHeaders.Cells for each rngCell NewField NewField.Name = rngCell.Value2 set as New field in NewField.Range = rngCell PFields.Add NewField next to RNGCell  

To do this:

  Set as RangeHeaders.Cells for each RNGLL as NewField field NewField = New Field NewField.Name = rngCell.Value2 Set NewField.Range = rngCell pFields.Add NewField Next RNGCell  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -