Looping Macro to Stop After Certain Cell Value is attained.

cpatel13

Board Regular
Joined
Jan 4, 2016
Messages
59
Hie,
So basically i have created a Excel File in which random numbers are generated. In which
A1 Input Value
A2 Low
A3High
These are the input values and the result is random numbers generated between the Low and high value, B5:B13 has this formula =ROUND(RANDBETWEEN($B$2,$B$3),-1). and B15 has this forumula =B1-SUM(B5:B13). Which gives me exactly the total when all the numbers in B5:B15 equals to the A1 which the input value, and C15 has this formula =IF(OR(B15<b2,b15>B3),"Failed","Success"), which states that whether the number is between the lower and higher value or not.Now what i have done is made an automation in the process, added a macro to help me. which is as follows:</b2,b15>

Sub Button5_Click()
Range("B5:B13").Calculate
End Sub

What i want is to run the macro untill C15 becomes success and when C15 becomes success the macro stops immediately.

Thanks Again.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hie,
So basically i have created a Excel File in which random numbers are generated. In which
A1 Input Value
A2 Low
A3High
These are the input values and the result is random numbers generated between the Low and high value, B5:B13 has this formula =ROUND(RANDBETWEEN($B$2,$B$3),-1). and B15 has this forumula =B1-SUM(B5:B13). Which gives me exactly the total when all the numbers in B5:B15 equals to the A1 which the input value, and C15 has this formula =IF(OR(B15<b2,b15>B3),"Failed","Success"), which states that whether the number is between the lower and higher value or not.Now what i have done is made an automation in the process, added a macro to help me. which is as follows:</b2,b15>

Sub Button5_Click()
Range("B5:B13").Calculate
End Sub

What i want is to run the macro untill C15 becomes success and when C15 becomes success the macro stops immediately.

Thanks Again.
Hi cpatel13, welcome to the boards,

If i am understanding you correctly then I think you can just do the following:

Rich (BB code):
Sub Button5_Click()
Do Until Range("C15").Value = "Success"
Range("B5:B13").Calculate
Loop
End Sub
 
Last edited:
Upvote 0
Thanks Fishboy, that's exactly what i was looking forward. thanks very much, i am trying to improvise the doc, i think so i may require a few more codes. but thanks again, you are genius.
 
Upvote 0
Thanks Fishboy, that's exactly what i was looking forward. thanks very much, i am trying to improvise the doc, i think so i may require a few more codes. but thanks again, you are genius.
No problem, happy to help. Many thanks for the positive feedback and pressing the Like button :)
 
Upvote 0

Forum statistics

Threads
1,216,075
Messages
6,128,662
Members
449,462
Latest member
Chislobog

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