I asked chatgpt to produce code and after trial and error it gave something that actually works. however it produced one that is not discriminating by judge types as I requested.
I told it judges from 1 to 8 are ordinary while 9 to 12 are special, and to assign a new judge in the third column based on the value of second column (ordinary or special) and turns, also the judge can't be the one in the first column.
It did something but then it takes the name of the judge from the array it made calling it judges while those are the turns of the judges to be assigned.
I need to modify the code so that there is actual dicrimination between ordinary and special in assigning a name, respecting the turn. Here is the code:
I told it judges from 1 to 8 are ordinary while 9 to 12 are special, and to assign a new judge in the third column based on the value of second column (ordinary or special) and turns, also the judge can't be the one in the first column.
It did something but then it takes the name of the judge from the array it made calling it judges while those are the turns of the judges to be assigned.
I need to modify the code so that there is actual dicrimination between ordinary and special in assigning a name, respecting the turn. Here is the code:
VBA Code:
Sub AssignJudges()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
Dim judgeCounter As Long
Dim turnCounter As Long
Dim judges As Variant
Set ws = ThisWorkbook.Worksheets("Rotation")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row ' Assuming the data starts from column A
' Define the judges and their rotation turns
judges = Array("Judge1", "Judge2", "Judge2", "Judge2", "Judge3", "Judge3", "Judge4", "Judge4", "Judge5", "Judge5", "Judge5", "Judge6", "Judge6", "Judge7", "Judge7", "Judge8", "Judge8", "Judge8", "Judge9", "Judge9", "Judge10", "Judge11", "Judge11", "Judge12", "Judge12")
' Start assigning judges from the first row to the last row
For i = 2 To lastRow
If ws.Cells(i, 1).value <> "" And ws.Cells(i, 2).value <> "" Then
If ws.Cells(i, 2).value = "Common" Then
' Assign any judge since the Kind is "Common"
ws.Cells(i, 3).value = GetNextJudge(judgeCounter, judges, turnCounter)
ElseIf ws.Cells(i, 2).value = "Ordinary" Then
' Assign only ordinary judges since the Kind is "Ordinary"
ws.Cells(i, 3).value = GetNextOrdinaryJudge(judgeCounter, judges, turnCounter)
End If
End If
Next i
End Sub
Function GetNextJudge(ByRef counter As Long, ByVal judges As Variant, ByRef turnCounter As Long) As String
' Increment the judge counter
counter = counter + 1
' Wrap around the counter if it exceeds the number of judges
If counter > UBound(judges) Then
counter = 0
End If
' Increment the turn counter if it's the judge's first turn
If counter = 0 Then
turnCounter = turnCounter + 1
End If
' Return the next judge
GetNextJudge = judges(counter)
End Function
Function GetNextOrdinaryJudge(ByRef counter As Long, ByVal judges As Variant, ByRef turnCounter As Long) As String
' Increment the ordinary judge counter
counter = counter + 1
' Wrap around the counter if it exceeds the number of ordinary judges
If counter > UBound(judges) Then
counter = 0
End If
' Increment the turn counter if it's the judge's first turn
If counter = 0 Then
turnCounter = turnCounter + 1
End If
' Return the next ordinary judge
GetNextOrdinaryJudge = judges(counter)
End Function