- Joined
- Feb 29, 2012
- Messages
- 1
- Reaction score
- 0
Good Day All
I will get straight to it. I have not done much with programming since BASIC was big . I am attempting to set up a template sheet to run scenarios on.
Here is my sad start to this task then I will explain what it is actually suppose to do.
Sub calctarget()
Dim x As Variant
Dim total As Double
Dim y As Variant
Dim target As Double
Dim RunTotal As Double
'y = ActiveCell.Offset(2, 0).Value
target = 11
For Each x In Range("A1:A15")
For Each y In Range("a1:a15").Offset(2, 0).Value
RunTotal = x + x.Offset(1, 0).Value
If RunTotal < target Then total = RunTotal + y
Next y
Next x
End Sub
Now this works through the first loop but then goes funny. I do not know enough to know if my approach is wrong.
The end goal is to Sum consecutive Cells until >= target. If > then target then subtract last cell from total so that it is not > target.
Then I need to select the cells making up the current total and apply an interior color
Next step would be to do this through entire range alternating interior colors for each set in range compared to target.
It would look something like this "target is actualy 44,500 in this example"
Thank you for any help or advice in advance
I will get straight to it. I have not done much with programming since BASIC was big . I am attempting to set up a template sheet to run scenarios on.
Here is my sad start to this task then I will explain what it is actually suppose to do.
Sub calctarget()
Dim x As Variant
Dim total As Double
Dim y As Variant
Dim target As Double
Dim RunTotal As Double
'y = ActiveCell.Offset(2, 0).Value
target = 11
For Each x In Range("A1:A15")
For Each y In Range("a1:a15").Offset(2, 0).Value
RunTotal = x + x.Offset(1, 0).Value
If RunTotal < target Then total = RunTotal + y
Next y
Next x
End Sub
Now this works through the first loop but then goes funny. I do not know enough to know if my approach is wrong.
The end goal is to Sum consecutive Cells until >= target. If > then target then subtract last cell from total so that it is not > target.
Then I need to select the cells making up the current total and apply an interior color
Next step would be to do this through entire range alternating interior colors for each set in range compared to target.
It would look something like this "target is actualy 44,500 in this example"
7585.1
0.0
10099.8
16700.0
16828.8
16828.8
8649.3
1212.4
5933.3
7934.1
9875.2
9875.2
11141.8
11313.5
2975.3
13592.0
13592.0
16286.0
5683.0
Thank you for any help or advice in advance