loderdodger
New Member
- Joined
- Jun 9, 2008
- Messages
- 7
Hi,
I have a loop that isn't working and it's beyond me what is causing the trouble. If anyone can notice what may be causing the issue I would be extremely grateful.
I have two loops, the first one works fine (which is why I want to show it), and the second one is basically the exact same operation just with different range references, and it is the second one that isn't working properly.
What is happening is that it should stop when: Range("SumMKT") <= Range("MKTBudget"). The loop does eventually stop, but it should be stopping earlier than it is. If it helps I can also explain that "SumMKT" is decreasing every time a cell is set to 0: Bcell.Offset(0, 4) = 0
I also wanted to add that the only thing that seems that different from the two loops is the:
Do Until Range("SumMKT") <= Range("MKTBudget")
However, I tried typing in the actual number so instead of Range("MKTBudget") I put in the constant (20,000,000) and it still doesn't work.
Thanks!
This is the first loop that is working fine:
Sub optimize()
Sheets("Optimization-Backend").Select
Dim Bcell As Range
Do Until Range("MKT_RD_belowBGT") = 1
For Each Bcell In Range("B2:B76")
If Bcell = Range("MinROI") Then
Bcell.Offset(0, 4) = 0
End If
Next Bcell
Loop
'Optimize1_stage2
End Sub
The second one:
Sub Optimize1_MKT()
MsgBox ("Optimize Marketing")
Dim Bcell As Range
Do Until Range("SumMKT") <= Range("MKTBudget")
For Each Bcell In Range("B52:B76")
If Bcell = Range("MinROI_MKT") Then
Bcell.Offset(0, 4) = 0
End If
Next Bcell
Loop
End Sub
I have a loop that isn't working and it's beyond me what is causing the trouble. If anyone can notice what may be causing the issue I would be extremely grateful.
I have two loops, the first one works fine (which is why I want to show it), and the second one is basically the exact same operation just with different range references, and it is the second one that isn't working properly.
What is happening is that it should stop when: Range("SumMKT") <= Range("MKTBudget"). The loop does eventually stop, but it should be stopping earlier than it is. If it helps I can also explain that "SumMKT" is decreasing every time a cell is set to 0: Bcell.Offset(0, 4) = 0
I also wanted to add that the only thing that seems that different from the two loops is the:
Do Until Range("SumMKT") <= Range("MKTBudget")
However, I tried typing in the actual number so instead of Range("MKTBudget") I put in the constant (20,000,000) and it still doesn't work.
Thanks!
This is the first loop that is working fine:
Sub optimize()
Sheets("Optimization-Backend").Select
Dim Bcell As Range
Do Until Range("MKT_RD_belowBGT") = 1
For Each Bcell In Range("B2:B76")
If Bcell = Range("MinROI") Then
Bcell.Offset(0, 4) = 0
End If
Next Bcell
Loop
'Optimize1_stage2
End Sub
The second one:
Sub Optimize1_MKT()
MsgBox ("Optimize Marketing")
Dim Bcell As Range
Do Until Range("SumMKT") <= Range("MKTBudget")
For Each Bcell In Range("B52:B76")
If Bcell = Range("MinROI_MKT") Then
Bcell.Offset(0, 4) = 0
End If
Next Bcell
Loop
End Sub
Last edited: