我会尽我所能来做到这一点。我有一个Excel工作表,需要对单元格进行求和,直到达到目标。然后这些单元需要一个内部颜色集。然后重置计算,然后继续下去,直到下一轮细胞等于目标。内部应该设置为不同的颜色。这将在整个范围内交替。我拥有它约90%,但第二种颜色只突出了集合的开始,然后继续第一种颜色。预先感谢您的任何指针Excel 2007 VBA Cell.interior基于连续单元格计算交替对目标
我:
Sub calctarget()
Dim x As Variant
Dim xsub As Variant
Dim total As Double
Dim y As Variant
Dim target As Double
Dim RunTotal As Double
target = 44500
If RunTotal < target Then y = 0
RunTotal = 0
For Each y In Range("a1:a15")
On Error Resume Next
RunTotal = RunTotal + y.Value
If RunTotal < target Then
y.Interior.ColorIndex = 4
End If
If RunTotal > target Then
RunTotal = RunTotal - y
If y.Offset(-1, 0).Interior.ColorIndex = 4 Then
RunTotal = 0
If RunTotal = 0 Then y.Interior.ColorIndex = 5
RunTotal = RunTotal + y
End If
End If
Next y
End Sub
我已经改变了缩进以使其更容易阅读 - 你能检查这是你的意思吗? – assylias 2012-03-12 15:10:44