我正在尝试使用数组复制以下代码,以避免重复代码 6 次。代码根据 1 的值为两个框着色,在本例中为 TueCum 和 TuePer - 我还有 WedCum、WedPer 等。
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
我已经走到这一步了,
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
但我似乎无法让它同时格式化两个文本框,我试过有第二个数组,但做错了。所以我需要让它在计算 TuePer 时为 TuePer 和 TueCum 着色,在计算 WedPer 时为 WedPer 和 WedCum 着色等。