Hi Brian,
Here I design some very draft...but quite complicate...just for light up some idea for any further development...
I use looping in Vba...try to give same logic..when we select the name manually...
I haven't try if it can be applied to other scenario...I think many adjustment needed to be amended in order to make it flexible for all scenario...let this be 1st step to start...
I list out the possibilities of group matching by number 1-6 then look up to find the name...see more in attachment!!!
- Here is the code
- Sub GroupGolfer()
lastList = WorksheetFunction.Max(Range("B:B"))
frtGrpRow = Range("F" & Rows.Count).End(xlUp).Row + 1
lastNmFrtGrp = Range("C1").Value
nxtNmFrtGrp = Range("C1").Value
Range("H2").Value = lastNmFrtGrp
roundCnt = 0
Do Until Range("H" & frtGrpRow).Value = ""
For y = 6 To 8
Cells(frtGrpRow, y).Select
For x = 1 To lastList
If ActiveCell.Value = "" Then
If WorksheetFunction.CountIf(Range("F" & frtGrpRow & ":H" & frtGrpRow), x) = 0 Then ActiveCell.Value = x
End If
Next x
Next y
If lastNmFrtGrp < lastList Then
lastNmFrtGrp = ActiveCell.Value + 1
Else
roundCnt = roundCnt + 1
lastNmFrtGrp = nxtNmFrtGrp + roundCnt
End If
If ActiveCell.Value = lastNmFrtGrp Then
MsgBox "First Group Done"
For i = 2 To Range("F" & Rows.Count).End(xlUp).Row
For Z = 12 To 10 Step -1
Cells(i, Z).Select
For x = 1 To lastList
If WorksheetFunction.CountIf(Range("F" & i & ":L" & i), x) = 0 Then ActiveCell.Value = x
Next x
Next Z
Next i
MsgBox "Done"
Exit Sub
Else
ActiveCell.Offset(1, 0).Value = lastNmFrtGrp
If ActiveCell.Offset(1, 0).Value < ActiveCell.Value Then ndNmFrtGrp = ActiveCell.Offset(0, -1).Value + 1
ActiveCell.Offset(1, -1).Value = ndNmFrtGrp
frtGrpRow = Range("F" & Rows.Count).End(xlUp).Row + 1
End If
Loop
End Sub
- Sample file for you...-->Vba_GolfArrangeGrp.zip
Hope you like it, let me know your feedback.
Pichart Y.