Decreasing Do Until loop

robbie95

New Member
Joined
Mar 3, 2016
Messages
2
Hi guys,
I'm pretty new to coding but I need it for a dissertation on auctions. Any help is greatly appreciated!!

A simplified version of what I am trying to achieve is to have a blank excel file with the number 10 in A1. I then want to run a Do Until loop with "A1 - 1" until it gets to zero, and post the result in cell B1. I can't do it with a counter as in my actual problem (second code) the value I need depends on when a solution changes. My attempt so far:

Code:
Sub Practiseloop()
Dim i As Integer
i = 0
Do Until Range("A1").Value = 0
A1 = A1 - (1 * i)
Debug.Print i
Loop
End Sub

I know this is a very simplified version but it should fix the code below!

Code:
Sub SuppFirstPriceOpenSolve()Dim i As Integer
i = 0
'keep going round the loop until the condition is true


Do Until Range("J24").Value = 0
I24 = I24 - (1000 * i)
    Range("J2: J278").Value = 0
    SolverReset
    SolverAdd CellRef:="$J$2:$J$278", Relation:=1, FormulaText:="1"
    SolverAdd CellRef:="$J$2:$J$278", Relation:=3, FormulaText:="0"
    SolverAdd CellRef:="$L$2:$L$8", Relation:=1, FormulaText:="$M$2:$M$8"
    SolverAdd CellRef:="$L$2:$L$8", Relation:=3, FormulaText:="0"
    SolverAdd CellRef:="$O$2:$T$2", Relation:=1, FormulaText:="$O$6:$T$6"
    SolverOk SetCell:="$O$8", MaxMinVal:=1, ValueOf:=0, ByChange:="$J$2:$J$278"
    SolverAdd CellRef:="$J$2:$J$278", Relation:=4, FormulaText:="integer"
    RunOpenSolver
Debug.Print i
Loop
End Sub
Thanks again,
Robbie
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
(1 * i) will always be i

So
A1 = A1 - (1 * i)
can be shortened to

A1 = A1 - i
 
Upvote 0
Thanks for the reply but later on I will have to do
A1 = A1 - (1000*i)
So I left it in the same format

My issue is that it the code does not work as intended
 
Upvote 0

Forum statistics

Threads
1,214,751
Messages
6,121,315
Members
449,025
Latest member
mikeloz11

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top