I’m working on a semi-automatic rota for my work; I am new to VBA but have other coding experience.
There is a ‘written table rota,’ where the start and end times of everyone is inputted, and the shift type is colour coordinated by text colour. And a ‘visualiser’ that outputs a visual schedule of when everyone is due in for the day.
I’ve made quite a lengthy if block for checking the text colour in the written table rota (Range("I" & table_row_number)
), with the intention of then colour-coordinating the visualiser to be the same colour (except for when the text is black – that would output a grey colour in the visualiser).
Every part of it works as intended, except for the final ‘elseif’ to check for ‘gym check yellow’ – it instead outputs an error message. I have absolutely no idea what is different between the other if statements and this one, since all the other statements work as intended and are seemingly identical in wording and style.
I have omitted the selection definition as it is unnecessary for the problem and would require me to define a lot more variables that are also not related to the problem, but to summarise, the selection is the range of cells that represents their shift in the visualiser. I know that the selection is working as intended as it highlights the correct cells.
For table_row_number = 6 To 100 Step 2
If Range("I" & table_row_number).Font.Color = RGB(0, 0, 0) Then
Selection.Interior.Color = RGB(165, 165, 165)
' Make the visualiser time-block bar grey (since black would be too bold)
ElseIf Range("I" & table_row_number).Font.Color = RGB(68, 114, 196) Then
Selection.Interior.Color = RGB(68, 114, 196)
' Make the visualiser time-block reception blue
ElseIf Range("I" & table_row_number).Font.Color = RGB(112, 173, 71) Then
Selection.Interior.Color = RGB(112, 173, 71)
' Make the visualiser time-block park cafe green
ElseIf Range("I" & table_row_number).Font.Color = RGB(237, 125, 49) Then
Selection.Interior.Color = RGB(237, 125, 49)
' Make the visualiser time-block padel shack orange
ElseIf Range("I" & table_row_number).Font.Color = RGB(225, 192, 0) Then
Selection.Interior.Color = RGB(255, 192, 0)
' Make the visualiser time-block gym check yellow
MsgBox "Gym Check Yellow"
Else
MsgBox "Error"
End If
Next
Thank you for reading and if anyone has any ideas on what is making yellow behave differently I would greatly appreciate the assistance <3
detra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.