Running and stopping a macro based on a cell value

c0087

Board Regular
Joined
Jul 13, 2015
Messages
94
Office Version
  1. 365
Platform
  1. Windows
Hi. I'm using =rand( for the data and setting it to 3 decimal place. As you know anytime you click, input, etc. in any cell, the =rand( automatically changes.

I want a macro, where I can continuously have it input something (i.e. in column D it just keep inputting "1 Enter") so it keeps changing my
data set until it reaches a certain number - let's say 0.001

based on the result in row 4, I want the macro to keep inputting 1 until one of those 3 values reaches STOP (indicating .001)

Any help/solution is much appreciated



[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]0.552[/TD]
[TD]0.252[/TD]
[TD]0.134[/TD]
[TD]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]=if(a2=.001,stop,go)[/TD]
[TD]=if(b2=.001,stop,go)[/TD]
[TD]if(c2=.001,stop,go)[/TD]
[TD]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]1
[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Does this do what you want..

Code:
Sub test()


    Do Until Range("A2").Value = 0.001 Or _
            Range("B2").Value = 0.001 Or _
            Range("C2").Value = 0.001
        Range("D2").Value = 1
    Loop
    
End Sub
 
Last edited:
Upvote 0
Instead of writing to a cell, you could trigger the recalc of RAND with the Calculate command

Code:
Do Until Range("A2").Value = 0.001 Or _
            Range("B2").Value = 0.001 Or _
            Range("C2").Value = 0.001

       Calculate
Loop
 
Upvote 0
I'm getting a compile error : invalid outside procedure on both tries.

I'm still new to code/macros, but all i did was copy/paste both your suggestions and got the same error
 
Upvote 0
Are you putting in a module in the Visual Basic Editor, and did you paste the entire code...

Also you may want to try to type it in. at the end of the first two lines is a blank and an underscore then hit enter and continue.
 
Upvote 0
It was calculating but not stopping at first, so i changed from rand( to randbetween using whole numbers and it works perfectly.

Thank you sir
 
Upvote 0
We were happy help. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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