I am trying to replicate the below code with arrays, to avoid repeating the code 6 times. The code colours two boxes based on the value of one, in this case TueCum and TuePer - I also have WedCum, WedPer etc.
If Val(TueCum) >= Val(ProdTarg) * ((2 * Sixth) + SixthLim) Then
TueCum.BackColor = &HFF00&
TuePer.BackColor = &HFF00&
ElseIf Val(TueCum) < Val(ProdTarg) * ((2 * Sixth) - SixthLim) Then
TueCum.BackColor = &HFF&
TuePer.BackColor = &HFF&
Else
TueCum.BackColor = &H80FF&
TuePer.BackColor = &H80FF&
End If
I have got this far,
Dim Cum(0 To 5)
Dim CDay As Variant
Count = 1
Set Cum(0) = MonCum
Set Cum(1) = TueCum
Set Cum(2) = WedCum
Set Cum(3) = ThuCum
Set Cum(4) = FriCum
Set Cum(5) = SatCum
For Each CDay In Cum
If Val(CDay) >= Val(ProdTarg) * ((Count * Sixth) + SixthLim) Then
CDay.BackColor = &HFF00&
TuePer.BackColor = &HFF00&
ElseIf Val(CDay) < Val(ProdTarg) * ((Count * Sixth) - SixthLim) Then
CDay.BackColor = &HFF&
TuePer.BackColor = &HFF&
Else
CDay.BackColor = &H80FF&
TuePer.BackColor = &H80FF&
End If
Count = Count + 1
Next CDay
But I can't seem to get it to format both textboxes at the same time, I have tried having a second array, but can't get it right. So I need to make it colour TuePer and TueCum when it calculates TuePer, colour WedPer and WedCum when it calculates WedPer, etc.