Combining Two Lists Into One Master List

Brian from Maui

MrExcel MVP
Joined
Feb 16, 2002
Messages
8,459
I'm trying to help a friend automate assigning tee times for a high school league invovling boys and girls.

I have a Boys list and a Girls list. The lists are unequal in size, with the boys having more players. I need to combine both lists into a master list to assign tee times. Each has a worksheet named Boys/Girls.

The criteria is to alternate, in groups of three, from each list, until all names are listed in the master list.

Like

Boy1
Boy2
Boy3
Girl1
Girl2
Girl3
Boy4
Boy5
Boy6
Girl4
Girl5
Girl6

I suppose, if worse comes to worst, I could manually do

=BoysList!A1

etc.

Any advice welcome.
 
Cool Jerry. Can I ask for one more tweek?

Separate columns for the 1st and 10th tees.

Name, School, Tee time, Tee number 1
Name, Scholl, Tee time, Team number 10?
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Oh I misunderstood that you wanted two separate sets of pairings.

Try this modified version of the main sub...
Code:
Sub MakePlayerPairings2StartTees()
'--builds two paring lists from two list of players
'  starting at different tees.
   Dim vTee1Data As Variant, vTee10Data As Variant

   '--read player data from two named ranges
   '  this example: Name, Team
   vTee1Data = Range("Tee1List").Value
   vTee10Data = Range("Tee10List").Value
     
   '--add a column to arrays with group numbers of pairings
   vTee1Data = vAssignGroups(vPlayers:=vTee1Data, _
      lFirstGroup:=1, lIncrementsGroupsBy:=1)
   vTee10Data = vAssignGroups(vPlayers:=vTee10Data, _
      lFirstGroup:=1, lIncrementsGroupsBy:=1)

   '--add a column to arrays with starting tees
   vTee1Data = vAddStartTees(vPlayers:=vTee1Data, _
      lStartTee:=1)
   vTee10Data = vAddStartTees(vPlayers:=vTee10Data, _
      lStartTee:=10)

   '--write results to new worksheet
   With Worksheets.Add
      '--write Tee 1 start data
      .Range("A1:D1") = Array("Name", "School", "Tee Time", "Tee Number")
      .Range("A2").Resize(UBound(vTee1Data, 1), _
         UBound(vTee1Data, 2)).Value = vTee1Data
      
      '--replace group numbers with tee times- Tee 1
      AssignTeeTimes rGroupNumbers:=.Range("C2:C" & _
         .Cells(.Rows.Count, "C").End(xlUp).Row), _
         dtStart:=TimeValue("08:30"), _
         dtIncrement:=TimeValue("00:08")
         
      '--write Tee 10 start data
      .Range("F1:i1") = Array("Name", "School", "Tee Time", "Tee Number")
      .Range("F2").Resize(UBound(vTee10Data, 1), _
         UBound(vTee10Data, 2)).Value = vTee10Data
      
      '--replace group numbers with tee times-Tee 10
      AssignTeeTimes rGroupNumbers:=.Range("H2:H" & _
         .Cells(.Rows.Count, "H").End(xlUp).Row), _
         dtStart:=TimeValue("08:30"), _
         dtIncrement:=TimeValue("00:08")
   
      .UsedRange.EntireColumn.AutoFit
   End With

End Sub
 
Upvote 0
Good Morning Jerry,

Thanks for you help. When I run the code, it errors at "Can't execute code at break mode" and the following is highlighted

vTee1Data = vAssignGroups(vPlayers:=vTee1Data, _
 
Upvote 0
Good Morning Brian, That error message indicates you were trying to restart the code after it already stopped at a breakpoint or error.

To track down the cause, Reset VBA (in the VBE Run > Reset), then try running again.
If it error's again, please post the error message, all the code of the procedure where the error occurred and note the statement that was highlighted when the error occurred.
 
Upvote 0
Did you copy the code in Post #22 into the same code module used for the previous examples?

The Sub "MakePlayerPairings2StartTees" code in Post #22 assumes the following functions are the same code module....
Private Function vAssignGroups (from Post #6)
Private Sub AssignTeeTimes (from Post #6)
Private Function vAddStartTees (from Post #17)
 
Upvote 0
Jerry,

My apologies, I'm a clutz when it comes to VBA. Do I combine the first code and the last one you provied or all three
 
Upvote 0
To clarify,

I copied the first and second codes you provided in the same module. Then I added the third in the same module also.

Was I suppose to insert the code in separate modules?
 
Upvote 0
It's Compile Error - Sub or function not defined

vAssignGroups is highlighted

It's ok Brian. This error implies that the function "vAssignGroups" is missing from a code module in which it is being called.

You could just delete all the code and paste these parts into one code module:

Sub MakePlayerPairings2StartTees code (from Post #22)
Private Function vAssignGroups (from Post #6)
Private Sub AssignTeeTimes (from Post #6)
Private Function vAddStartTees (from Post #17)

Optional: If you are still using the Boys/Girls code in this workbook, also add...
Sub MakePlayerPairingsList (from Post #6)
 
Upvote 0
Jerry,
As of right now I have this procedure in one module

Code:
Sub MakePlayerPairingsList()
   Dim vBoysNames As Variant, vGirlsNames As Variant
   Dim vAllNames As Variant, vResults As Variant
   '--read names from two named ranges (add validation if needed)
   vBoysNames = Range("BoysList").Value
   vGirlsNames = Range("GirlsList").Value
  
   '--add a column to arrays with group numbers of pairings
   vBoysNames = vAssignGroups(vPlayers:=vBoysNames, _
      lFirstGroup:=1, lIncrementsGroupsBy:=2)
   vGirlsNames = vAssignGroups(vPlayers:=vGirlsNames, _
      lFirstGroup:=2, lIncrementsGroupsBy:=2)
   '--write results to new worksheet
   With Worksheets.Add
      .Range("A2").Resize(UBound(vBoysNames, 1), _
         UBound(vBoysNames, 2)).Value = vBoysNames
      .Range("A2").Offset(UBound(vBoysNames, 1)) _
         .Resize(UBound(vGirlsNames, 1), _
         UBound(vGirlsNames, 2)).Value = vGirlsNames
      With .Range("A1").CurrentRegion
          .Sort Key1:=.Range("B1"), Order1:=xlAscending, _
          Header:=xlYes, Orientation:=xlTopToBottom
      End With
      
      '--replace group numbers with tee times
      AssignTeeTimes rGroupNumbers:=.Range("B2:B" & _
         .Cells(.Rows.Count, "B").End(xlUp).Row), _
         dtStart:=TimeValue("08:30"), _
         dtIncrement:=TimeValue("00:08")
         
      .Range("A1:B1") = Array("Player Name", "Tee Time")
      .UsedRange.EntireColumn.AutoFit
   End With
End Sub

Private Sub AssignTeeTimes(ByVal rGroupNumbers As Range, _
   ByVal dtStart As Date, ByVal dtIncrement As Date)
            
   Dim dtTeeTime As Date
   Dim sLastGroup As String
   Dim rGroup As Range
   
   '--initial values
   dtTeeTime = dtStart
   sLastGroup = rGroupNumbers(1)
   
   For Each rGroup In rGroupNumbers
      If rGroup.Value <> sLastGroup Then
         '--next group
         sLastGroup = rGroup.Value
         dtTeeTime = dtTeeTime + dtIncrement
      End If
      rGroup.Value = dtTeeTime
   Next rGroup
   rGroupNumbers.NumberFormat = "h:mm AM/PM"
End Sub
            
Private Function vAssignGroups(ByVal vPlayers As Variant, _
   ByVal lFirstGroup As Long, ByVal lIncrementsGroupsBy As Long) As Variant
'---assumes input vPlayers is a 2D array and first column has players names.
'   Returns array that has added column with group numbers of pairings.
'   Assigns 3 players per group until need to switch to
'   4 players per groups to have remainder of 0.
'   Group numbers start at lFirstGroup and increase by lIncrementsGroupsBy
   Dim lCountOfPlayers As Long, lLastInThreesome As Long
   Dim lSpotsInGroup As Long, lSpotsOpen As Long
   Dim lGroup As Long, lNdx As Long, lGroupCol As Long
   
   lGroupCol = UBound(vPlayers, 2) + 1
   lCountOfPlayers = UBound(vPlayers, 1)
   
   '--adds a field for Group Assignments
   ReDim Preserve vPlayers(1 To lCountOfPlayers, 1 To lGroupCol)
 
   '--calculate when groups must switch to foursomes
   lLastInThreesome = lCountOfPlayers - 4 * (lCountOfPlayers Mod 3)
      
   '--start with 3 per group except case of 4 or 8 players
   Select Case lCountOfPlayers
      Case 4, 8: lSpotsInGroup = 4
      Case Else: lSpotsInGroup = 3
   End Select
   lSpotsOpen = lSpotsInGroup
   lGroup = lFirstGroup
   
   For lNdx = 1 To lCountOfPlayers
      If lSpotsOpen = 0 Then
         '--start new group with all spots open
         lGroup = lGroup + lIncrementsGroupsBy
         lSpotsOpen = lSpotsInGroup
      End If
      
      '--assign group to player
      vPlayers(lNdx, lGroupCol) = lGroup
      lSpotsOpen = lSpotsOpen - 1
      
      If lNdx = lLastInThreesome Then
         lSpotsInGroup = 4
      End If
      
   Next lNdx
   vAssignGroups = vPlayers
End Function
Sub MakePlayerPairings2StartTees()
'--builds two paring lists from two list of players
'  starting at different tees.
   Dim vTee1Data As Variant, vTee10Data As Variant
   '--read player data from two named ranges
   '  this example: Name, Team
   vTee1Data = Range("Tee1List").Value
   vTee10Data = Range("Tee10List").Value
     
   '--add a column to arrays with group numbers of pairings
   vTee1Data = vAssignGroups(vPlayers:=vTee1Data, _
      lFirstGroup:=1, lIncrementsGroupsBy:=1)
   vTee10Data = vAssignGroups(vPlayers:=vTee10Data, _
      lFirstGroup:=1, lIncrementsGroupsBy:=1)
   '--add a column to arrays with starting tees
   vTee1Data = vAddStartTees(vPlayers:=vTee1Data, _
      lStartTee:=1)
   vTee10Data = vAddStartTees(vPlayers:=vTee10Data, _
      lStartTee:=10)
   '--write results to new worksheet
   With Worksheets.Add
      '--write Tee 1 start data
      .Range("A1:D1") = Array("Name", "School", "Tee Time", "Tee Number")
      .Range("A2").Resize(UBound(vTee1Data, 1), _
         UBound(vTee1Data, 2)).Value = vTee1Data
      
      '--replace group numbers with tee times- Tee 1
      AssignTeeTimes rGroupNumbers:=.Range("C2:C" & _
         .Cells(.Rows.Count, "C").End(xlUp).Row), _
         dtStart:=TimeValue("08:30"), _
         dtIncrement:=TimeValue("00:08")
         
      '--write Tee 10 start data
      .Range("F1:i1") = Array("Name", "School", "Tee Time", "Tee Number")
      .Range("F2").Resize(UBound(vTee10Data, 1), _
         UBound(vTee10Data, 2)).Value = vTee10Data
      
      '--replace group numbers with tee times-Tee 10
      AssignTeeTimes rGroupNumbers:=.Range("H2:H" & _
         .Cells(.Rows.Count, "H").End(xlUp).Row), _
         dtStart:=TimeValue("08:30"), _
         dtIncrement:=TimeValue("00:08")
   
      .UsedRange.EntireColumn.AutoFit
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,326
Messages
6,124,270
Members
449,149
Latest member
mwdbActuary

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