Forum Discussion
Help with VBA Code
- May 14, 2025
That looks great and works when I added it to the workbook! Thank you for your help!
So I chose to do this in a worksheet function. This can be a unique LAMBDA function and then you can have multiple LAMBDA functions for different games. In this case I made a function that should work for BOTH those games (i.e. take SUM and subtract worst Score for each hole)
here is a breakdown of the function:
=LET(pTeams, Table1[Team '#], pHDCP, Table1[HDCP], pRaw, HSTACK(Table1[[1]:[9]],Table1[[10]:[18]]),
HDCP, HSTACK(H12:P12,R12:Z12), Par, HSTACK(H13:P13,R13:Z13),
NetScores, pRaw-(pHDCP>=HDCP),
NetTeam, MAP(UNIQUE(pTeams),LAMBDA(I, SUM(BYCOL(FILTER(NetScores,pTeams=I), LAMBDA(c, SUM(c)-MAX(c)))))),
HSTACK(UNIQUE(pTeams),NetTeam))So I did format the raw data as a TABLE but not required.
Row 1 gets the column of Team #s, the column of player HDCP, the player Raw scores (1-18 without the 'IN')
Row 2 gets the HDCP (again without the extra space) and the Par (but I just realized I forgot to subtract Par, but that is easy enough)
Row 3 finds the Net Score for EACH player for EACH hole.
Row 4 loops through each TEAM and then loops through each HOLE and takes the SUM-MAX to find the Team's score for that hole
Row 5 outputs the list of Team#s and final Scores