Excel/VBA Soccer/Football Lineup Generator

haluxuxjr

New Member
Joined
Mar 1, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi, everybody!

I would like to request some assistance for the following: each weekend me and a group of friends play a football match ( 7vs7 ), and we always have trouble when making the starting lineups, so I want to create a formula or a macro that can create random, balanced teams based on the player's positions and skills.

Initially I have 3 columns: player name, position (GK - goalkeeper, DF - defender and AT - attacker) and skill (from 1 to 5).

I have to fill a lineup that deploys 2 teams with 1 GK, 3 DF and 3 AT each, trying that each squad is balanced (skill) and the players play in their preferred position.

It would be very interesting to find a way to add this consideration into the lineup generator.

Thank you in advance!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Welcome to the MrExcel forum!

A few years back, I wrote a macro that pretty much does what you want. And it appears you found a copy of it in the other thread you are in. The main difference is that that macro has the MF position. You could probably make it work by assigning some of your players as MF, or I could update the macro. But with the advent of some new functions, I tried to do it with formulas. Consider:

Book1
ABCDEFGHIJKLMNO
1NamePositionSkillTeam ATotal SkillTeam BTotal SkillDifferenceTeam ATotal SkillTeam BTotal SkillDifference
2aGK2a,c,d,e,i,j,k21b,h,g,f,n,m,l232a,c,d,e,i,j,n22b,h,g,f,n,m,i220
3bGK4a,c,d,e,i,j,l21b,h,g,f,n,m,k232a,c,d,e,i,k,n22b,h,g,f,n,l,i220
4cDF3a,c,d,e,i,j,m18b,h,g,f,n,m,j268a,c,d,e,i,l,n22b,h,g,f,n,k,i220
5dDF5a,c,d,e,i,j,n22b,h,g,f,n,m,i220a,c,d,f,i,j,k22b,h,g,e,n,m,l220
6eDF1a,c,d,e,i,k,l21b,h,g,f,n,l,k232a,c,d,f,i,j,l22b,h,g,e,n,m,k220
7fDF2a,c,d,e,i,k,m18b,h,g,f,n,l,j268a,c,d,f,i,k,l22b,h,g,e,n,l,k220
8gDF3a,c,d,e,i,k,n22b,h,g,f,n,l,i220a,c,d,f,j,m,n22b,h,g,e,m,j,i220
9hDF4a,c,d,e,i,l,m18b,h,g,f,n,k,j268a,c,d,f,k,m,n22b,h,g,e,l,j,i220
10iAT2a,c,d,e,i,l,n22b,h,g,f,n,k,i220a,c,d,f,l,m,n22b,h,g,e,k,j,i220
11jAT4a,c,d,e,i,m,n19b,h,g,f,n,j,i256a,c,d,g,j,k,m22b,h,g,d,m,l,j220
12kAT4a,c,d,e,j,k,l23b,h,g,f,m,l,k212a,c,d,g,j,l,m22b,h,g,d,m,k,j220
13lAT4a,c,d,e,j,k,m20b,h,g,f,m,l,j244a,c,d,g,k,l,m22b,h,g,d,l,k,j220
14mAT1a,c,d,e,j,k,n24b,h,g,f,m,l,i204a,c,d,h,i,m,n22b,h,g,c,n,j,i220
15nAT5a,c,d,e,j,l,m20b,h,g,f,m,k,j244a,c,e,g,j,k,n22b,h,f,d,m,l,i220
16a,c,d,e,j,l,n24b,h,g,f,m,k,i204a,c,e,g,j,l,n22b,h,f,d,m,k,i220
17a,c,d,e,j,m,n21b,h,g,f,m,j,i232a,c,e,g,k,l,n22b,h,f,d,l,k,i220
18a,c,d,e,k,l,m20b,h,g,f,l,k,j244a,c,e,h,j,k,l22b,h,f,c,m,l,k220
19a,c,d,e,k,l,n24b,h,g,f,l,k,i204a,c,f,g,j,k,l22b,h,e,d,m,l,k220
20a,c,d,e,k,m,n21b,h,g,f,l,j,i232a,c,f,h,i,j,n22b,h,e,c,n,m,i220
21a,c,d,e,l,m,n21b,h,g,f,k,j,i232a,c,f,h,i,k,n22b,h,e,c,n,l,i220
22a,c,d,f,i,j,k22b,h,g,e,n,m,l220a,c,f,h,i,l,n22b,h,e,c,n,k,i220
Sheet4
Cell Formulas
RangeFormula
E2:E801E2=LET(d,A2:C15,gk,FILTER(d,B2:B15="gk"),df,FILTER(d,B2:B15="df"),at,FILTER(d,B2:B15="at"),s,BASE(SEQUENCE(93312,,0),6,7),t,IF((MID(s,2,1)>=MID(s,3,1))+(MID(s,2,1)>=MID(s,4,1))+(MID(s,3,1)>=MID(s,4,1))+(MID(s,5,1)>=MID(s,6,1))+(MID(s,5,1)>=MID(s,7,1))+(MID(s,6,1)>=MID(s,7,1)),"",INDEX(gk,LEFT(s)+1,1)&","&INDEX(df,MID(s,2,1)+1,1)&","&INDEX(df,MID(s,3,1)+1,1)&","&INDEX(df,MID(s,4,1)+1,1)&","&INDEX(at,MID(s,5,1)+1,1)&","&INDEX(at,MID(s,6,1)+1,1)&","&INDEX(at,MID(s,7,1)+1,1)),tf,FILTER(t,t<>""),tf)
F2:F801F2=LET(d,A2:C15,gk,FILTER(d,B2:B15="gk"),df,FILTER(d,B2:B15="df"),at,FILTER(d,B2:B15="at"),s,BASE(SEQUENCE(93312,,0),6,7),t,IF((MID(s,2,1)>=MID(s,3,1))+(MID(s,2,1)>=MID(s,4,1))+(MID(s,3,1)>=MID(s,4,1))+(MID(s,5,1)>=MID(s,6,1))+(MID(s,5,1)>=MID(s,7,1))+(MID(s,6,1)>=MID(s,7,1)),"",INDEX(gk,LEFT(s)+1,3)+INDEX(df,MID(s,2,1)+1,3)+INDEX(df,MID(s,3,1)+1,3)+INDEX(df,MID(s,4,1)+1,3)+INDEX(at,MID(s,5,1)+1,3)+INDEX(at,MID(s,6,1)+1,3)+INDEX(at,MID(s,7,1)+1,3)),tf,FILTER(t,t<>""),tf)
G2:G801G2=LET(d,A2:C15,gk,FILTER(d,B2:B15="gk"),df,FILTER(d,B2:B15="df"),at,FILTER(d,B2:B15="at"),s,BASE(SEQUENCE(93312,,0),6,7),t,IF((MID(s,2,1)>=MID(s,3,1))+(MID(s,2,1)>=MID(s,4,1))+(MID(s,3,1)>=MID(s,4,1))+(MID(s,5,1)>=MID(s,6,1))+(MID(s,5,1)>=MID(s,7,1))+(MID(s,6,1)>=MID(s,7,1)),"",INDEX(gk,2-LEFT(s),1)&","&INDEX(df,6-MID(s,2,1),1)&","&INDEX(df,6-MID(s,3,1),1)&","&INDEX(df,6-MID(s,4,1),1)&","&INDEX(at,6-MID(s,5,1),1)&","&INDEX(at,6-MID(s,6,1),1)&","&INDEX(at,6-MID(s,7,1),1)),tf,FILTER(t,t<>""),tf)
H2:H801H2=SUM(C2:C15)-F2#
I2:I801I2=ABS(F2#-H2#)
K2:O801K2=SORTBY(E2:I801,I2:I801)
Dynamic array formulas.


I started with the table in A1:C15. It doesn't need to be sorted by position, but there must be EXACTLY 2 GK, 6 DF, and 6 AT. Then the formula at E2 figures out every combination of a valid team, F2 gets the total skill, G2 gets the opposite team, H2 gets the opposite teams skill, and I2 gets the difference. Then the K2 formula merely sorts that table by difference. So you can see right off what combinations will work for you. I considered adding a RANDARRAY to it, so that instead of showing everything in the same order every time, it would mix up all the teams with the same difference. That formula would look like:

Excel Formula:
=SORTBY(E2:I801,I2:I801,1,RANDARRAY(800),1)

Let me know what you think!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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