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
 

Some videos you may like

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Special-K99

Well-known Member
Joined
Nov 7, 2006
Messages
8,350
(1 * i) will always be i

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

A1 = A1 - i
 

robbie95

New Member
Joined
Mar 3, 2016
Messages
2
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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,307
Messages
5,600,869
Members
414,411
Latest member
Snowmanaus

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
Top