Collection Properties in common

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,355
I am working with custom classes. Two classes in particular, clsPeople and clsWorkingGroup. A clsWorkingGroup object is basically a collection of clsPeople objects.
A clsPeople object has a WorkingGroup property which is the clsWorkgingGroup object which that person is a member of.

I can add and remove individual clsPeople to a clsWorkingGroup fine. Individual changes to APerson.WorkingGroup are reflected in the .WorkingGroup property of the other member's of that group.

My difficulty is when I try to merge two WorkingGroups. If I have APerson.WorkingGroup and BPerson.WorkingGroup and merge them, I could either

1) add all the members of APerson.WorkingGroup to BPerson.WorkingGroup and vice-versa. The problem is that would result in two different clsWorkingGroup objects with the same members, but different objects. Future changes to APerson.WorkingGroup would not be reflected in BPerson.WorkingGroup.

2) or I could create a new clsWorkingGroup object, fill it with the members of both APerson.WorkingGroup and BPerson.WorkingGroup and then go back and assign that new group to the WorkingGroup property of everyone's clsPerson object. That would work fine but consider

VBA Code:
' pseudo code
Dim OneGroup as clsWorkingGroup

Set oneGroup = APerson.WorkingGroup

MergeGroups APerson.WorkingGroup, BPerson.WorkingGroup

' what of oneGroup.

The difficulty with 2) is that any previous variables of those WorkingGroups lose their value when merged.

How can I merge two clsWorkingGroup objects so that they become one object, but without losing the value that previous arguments might have to one or the other of those clsWorkingGroup objects?

Unless I can find a solution to this dilemma, I'm going to have to go with #2.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,214,518
Messages
6,119,996
Members
448,935
Latest member
ijat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top