I am creating a userform on excel 2007 that has a 6x6 arrangement of combo boxes. the last row and last column are the 'all up' boxes that should have a value based on their respective rows/columns. the remaining 25 (5x5) combo boxes have 3 values (Red, Amber, Green), and when a user selects a value, the combo box displays the value and the background is coloured with the value selected (I did this by creating a function in a module and calling it within each combobox_change()).
I am having trouble coding the last row and column boxes. Basically, if say for Row 1, there is even a single 'Red', the last box on row 1 (1,6) should automatically turn red. If there is no red, but there is an 'amber', the last box should turn 'amber'. If there is a 'red' and an 'amber', 'red' should be given the priority. Similar logic for columns as well.
What I have tried so far:
Within the userform code:
Private Sub Txt_Score_1_1_Change() 'This is for row 1 column 1 on the matrix'
Call ScoreChange.ScoreChange("Txt_Score_1_1")
Within a module:
Public Sub ScoreChange(ctrlName As String)
If Scorecard.Controls(ctrlName).Value = "R" Then
Scorecard.Controls(ctrlName).BackColor = vbRed
ElseIf Scorecard.Controls(ctrlName).Value = "G" Then
Scorecard.Controls(ctrlName).BackColor = vbGreen
ElseIf Scorecard.Controls(ctrlName).Value = "A" Then
Scorecard.Controls(ctrlName).BackColor = vbYellow
Else
Scorecard.Controls(ctrlName).BackColor = vbWhite
End If
For i = 1 To 5
For j = 1 To 5
If Scorecard.Controls("Txt_Score_" & i & "_" & j).Value <> "" Then
If Scorecard.Controls("Txt_Score_" & i & "_" & j).Value = "R" Then
Scorecard.Controls("Txt_Score_" & i & "_6").Value = "R"
Scorecard.Controls("Txt_Score_6_" & j).Value = "R"
ElseIf Scorecard.Controls("Txt_Score_" & i & "_" & j).Value = "A" Then
Scorecard.Controls("Txt_Score_" & i & "_6").Value = "A"
Scorecard.Controls("Txt_Score_6_" & j).Value = "A"
End If
End If
Next j
Next i
End Sub
The above works to change the individual colours of the combo boxes when changed but falls apart for the 'total'/'all up' boxes.
What I think needs to be done to achieve the above is that I need to write a code that recognises when all the combo boxes for a specific row/column have been filled, and then stores those values in an array, and recognises within the array, the value for the last box.
Any help on how to achieve this will be appreciated.
Also, apologies if something similar has been posted elsewhere, but I did a lot of research and couldn't find anything.
Thanks.