Running and stopping a macro based on a cell value

c0087

Board Regular
Joined
Jul 13, 2015
Messages
79
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



0.5520.2520.1341
1
=if(a2=.001,stop,go)=if(b2=.001,stop,go)if(c2=.001,stop,go)1
1

<tbody>
</tbody>
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 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,213,497
Messages
6,113,999
Members
448,543
Latest member
MartinLarkin

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