Two Range lookup and insert to discreet ranges on another worksheet

cubewarrior

New Member
Joined
Dec 11, 2014
Messages
29
Excel Gurus,
First off I have found this forum to be amazingly talented and helpful (as well as educational) in the few times I needed help. I am on a PC with Excel 2013 and I am looking for two-fold help:
1) I am looking to insert nested data into specific targetted areas of a blank template. By nested, I mean Insert a range from one table and also insert another range as children to the parent insert by reference to another table.
2) I am looking to understand the code, as I am hoping to learn the hows and whys for my education.
From a taxonomy perspective I think of my data as such:
1) EventMaster Defines Events, Days, and Teams (as well as order of each)
2) TeamMaster Defines Teams, Team Members, and Departments
I am looking to populate an Event card that has a few discrete ranges for data to populate to (By Day), with the Events and Teams from EventMaster (Aligned with Day on template) as well as individual Team Members and Departments matched from Team in EventMaster to Team Members and Department from TeamMaster.
I have a master list of my team members (Sheet "TeamMaster")
Excel 2012
ABCDEFGH
1Team NameFirst NameLast NameRoleDeptCommitmentAvailableContact
2Blue TeamTomBradyLeadLegalHighYY
3Blue TeamRobGronkowskiCrewLegalLowYY
4Blue TeamBillBellicheckCrewLegalLowYN
5Green TeamAdamSandlerLeadSalesHighYY
6Green TeamJackBlackCrewSalesMedYN
7Green TeamDaneCookCrewSalesMedYN
8Yellow TeamPeter ParkerLeadOperationsHighYY
9Yellow TeamScottSummersCrewOperationsLowYN
10Pink TeamJohnSmithLeadAdministrationLowYY
11Pink TeamJaneSmithCrewAdministrationHighYN
12Red TeamWinstonChurchillLeadProgram MgmtMedYY
13Red TeamGeorgePattonCrewProgram MgmtMedYN
14Red TeamTheodoreRooseveltCrewProgram MgmtMedYN
15Red TeamAlbertEinsteinCrewProgram MgmtMedYN

<colgroup><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
TeamMaster



I have a master list of the planned events (Sheet "EventMaster")

Excel 2012
ABC
1EventDayTeam
2Event - Race1Green
3Event - Race1Red
4Event - Race1Blue
5Event - Obstacles1Pink
6Event - Obstacles1Yellow
7Event - Obstacles1Green
8Event - Trivia2Yellow
9Event - Trivia2Red
10Event - Trivia2Pink
11Event - Acronym Match2Green
12Event - Acronym Match2Blue
13Event - Acronym Match2Red

<colgroup><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
EventMaster



I am looking for a Sub that I can assign to a button control that will go to sheet "EventCard" and, for a given day insert a nested return results, being the Event assigned to a given day as well as the team (From "EventMaster) plus insert/expand with the results of the Team (From EventMaster list from sheet "EventMaster" cross referenced with the Team Members from the TeamMaster list on sheet "TeamMaster"). Example of Day 1 desired population below:

Excel 2012
BCDEFGHIJKL
2Day 1Day 2
3EventTeamTeam MembersDepartmentEventTeamTeam MembersDepartment
4First NameLast NameFirst NameLast Name
5Event - RaceGreenAdamSandlerSales
6Event - RaceGreenJackBlackSales
7Event - RaceGreenDaneCookSales
8Event - RaceRedWinstonChurchillProgram Mgmt
9Event - RaceRedGeorgePattonProgram Mgmt
10Event - RaceRedTheodoreRooseveltProgram Mgmt
11Event - RaceRedAlbertEinsteinProgram Mgmt
12Event - RaceBlueTomBradyLegal
13Event - RaceBlueRobGronkowskiLegal
14Event - RaceBlueBillBellicheckLegal
15Event - ObstaclesPinkJohnSmithAdministration
16Event - ObstaclesPinkJaneSmithAdministration
17Event - ObstaclesYellowPeter ParkerOperations
18Event - ObstaclesYellowScottSummersOperations
19Event - ObstaclesGreenAdamSandlerSales
20Event - ObstaclesGreenJackBlackSales
21Event - ObstaclesGreenDaneCookSales

<colgroup><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
EventCard


Any help very appreciated
- CW
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try this:-
Results start "A1" of sheet "EventCard"
Code:
[COLOR="Navy"]Sub[/COLOR] MG21Dec37
[COLOR="Navy"]Dim[/COLOR] RngT [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] RngE [COLOR="Navy"]As[/COLOR] Range, c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Temp [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer[/COLOR]
[COLOR="Navy"]With[/COLOR] Sheets("TeamMaster")
    [COLOR="Navy"]Set[/COLOR] RngT = .Range(.Range("A2"), .Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
    .CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] RngT
    [COLOR="Navy"]If[/COLOR] Not .Exists(Split(Dn.Value, " ")(0)) [COLOR="Navy"]Then[/COLOR]
        .Add Split(Dn.Value, " ")(0), Dn
    [COLOR="Navy"]Else[/COLOR]
        [COLOR="Navy"]Set[/COLOR] .Item(Split(Dn.Value, " ")(0)) = Union(.Item(Split(Dn.Value, " ")(0)), Dn)
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]With[/COLOR] Sheets("EventMaster")
    [COLOR="Navy"]Set[/COLOR] RngE = .Range(.Range("A2"), .Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]End[/COLOR] With


c = 3
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] RngE.Offset(, 2).Resize(RngE.Count + 1)
[COLOR="Navy"]If[/COLOR] Not Dn.Offset(, -1).Value = Temp Or Dn = "" [COLOR="Navy"]Then[/COLOR]
    [COLOR="Navy"]If[/COLOR] Ac = 0 [COLOR="Navy"]Then[/COLOR]
        ReDim ray(1 To RngE.Count + RngT.Count + 3, 1 To 5)
        ray(2, 1) = "Event": ray(2, 2) = "Team": ray(2, 3) = "Team Members": ray(2, 5) = "Department"
        ray(3, 3) = "First Name": ray(3, 4) = "Last Name"
        Ac = Ac + 1
    [COLOR="Navy"]Else[/COLOR]
        Sheets("EventCard").Cells(1, Ac).Resize(c, 5).Value = ray
        [COLOR="Navy"]If[/COLOR] Dn.Value = "" [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Exit[/COLOR] [COLOR="Navy"]Sub[/COLOR]
        ReDim ray(1 To RngE.Count + RngT.Count + 3, 1 To 5)
        ray(2, 1) = "Event": ray(2, 2) = "Team": ray(2, 3) = "Team Members": ray(2, 5) = "Department"
        ray(3, 3) = "First Name": ray(3, 4) = "Last Name"
        Ac = Ac + 6
        c = 3
    [COLOR="Navy"]End[/COLOR] If
 [COLOR="Navy"]End[/COLOR] If


[COLOR="Navy"]For[/COLOR] n = 1 To .Item(Dn.Value).Count
    c = c + 1
    ray(1, 1) = "Day " & Dn.Offset(, -1).Value
    ray(c, 1) = Dn.Offset(, -2).Value: ray(c, 2) = Dn.Value: ray(c, 3) = .Item(Dn.Value)(n).Offset(, 1).Value
    ray(c, 4) = .Item(Dn.Value)(n).Offset(, 2).Value: ray(c, 5) = .Item(Dn.Value)(n).Offset(, 4).Value
[COLOR="Navy"]Next[/COLOR] n
    Temp = Dn.Offset(, -1)
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,181
Members
449,071
Latest member
cdnMech

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