Collection Properties in common

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,983
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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Watch MrExcel Video

Forum statistics

Threads
1,129,569
Messages
5,637,099
Members
416,957
Latest member
Brovashift

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
Top