I will do what I can to make this short and sweet. I have an excel Work sheet that needs to sum cells until it reaches the target. Then those cells need an interior color set. The calculations then reset then continue down the range until the next run of cells equals target. The interior should the set to a different color for this set. This would alternate through the range. I have it about 90 % but the second color only highlights for the start of the set and then continues with the first color. Thank you in advance for any pointers
I have :
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
This is maybe what you need (it alternates colors every time the target is reached and carries the balance forward if any):