0
我想複製下面的代碼與數組,以避免重複代碼6次。 代碼顏色的兩個基於一個值,在這種情況下TueCum和TuePer盒子 - 我也有WedCum,WedPer等PowerPoint VBA - For循環和陣列
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和TueCum當計算TuePer,顏色WedPer和WedCum當計算WedPer等
喜@ d-stroyer,謝謝! 這很棒,我必須做的一點點改變,就是'If Val(Cum(Count))> = Val(ProdTarg)' 再次感謝您的幫助! – Conquistador
+1不錯的答案。 – brettdj