jlhoover3
Board Regular
- Joined
- Nov 9, 2015
- Messages
- 60
- Office Version
- 365
- Platform
- Windows
Good Morning! I'm trying to build a golf pairing list for our Men's Group Association, but the code is really kicking my butt. Long story short, I'm trying to build an excel sheet to create my pairings and groups based on a range of cells. I want the pairings to go in snake order based on their value of points. This also has to be based on what their input is on how many teams their should be.
For example above, Players are in order based on points, and now I want vba to get me the result in Range(E2:I3). I want the mod = 1 to go to the last group. Hope this makes sense. The players list can range anywhere from 4 to unlimited, as well as Groups. The player list will be calculated based on whomever has checked in. The VBA will ask the question on how many groups you are wanting. I found the code below, but it's not exactly what I'm looking for. Very close! I'm trying to play around with it to get what I need. Thanks again!
A | B | C | D | E | F | G | H | I |
Player | Points | Player A | Player B | Player C | Player D | Player E | ||
Player 1 | 13.5 | Group #1 | Player 1 | Player 4 | Player 5 | |||
Player 2 | 12.5 | Group #2 | Player 2 | Player 3 | Player 6 | Player 7 | ||
Player 3 | 11 | |||||||
Player 4 | 10.5 | |||||||
Player 5 | 8 | |||||||
Player 6 | 7 | |||||||
Player 7 | 6 |
For example above, Players are in order based on points, and now I want vba to get me the result in Range(E2:I3). I want the mod = 1 to go to the last group. Hope this makes sense. The players list can range anywhere from 4 to unlimited, as well as Groups. The player list will be calculated based on whomever has checked in. The VBA will ask the question on how many groups you are wanting. I found the code below, but it's not exactly what I'm looking for. Very close! I'm trying to play around with it to get what I need. Thanks again!
VBA Code:
Sub MyMacro()
Dim teams As Long
Dim rounds As Long
Dim c As Long
Dim r As Long
Dim i As Long
Dim hr As Long
Dim hc As Long
Application.ScreenUpdating = False
' Indicate number of header rows and columns
hr = 5
hc = 1
' Prompt for number of teams
teams = InputBox("How many teams are there?")
' Prompt for number of rounds
rounds = InputBox("How many rounds are there?")
' Populate data, starting in row 2
For r = 1 To rounds
' Populate columns, starting in column A
If (r Mod 2) = 1 Then
' Go forward
For c = 1 To teams
i = i + 1
Cells(r + hr, c + hc) = i
Next c
Else
' Go backward
For c = teams To 1 Step -1
i = i + 1
Cells(r + hr, c + hc) = i
Next c
End If
Next r
Application.ScreenUpdating = True
End Sub