Dear All,
I hope this has not been answered on this forums, I tried to search for a solution but have reached this far (see below code).
The problem: I have sheet where i want to simulate a certain process. I generate random numbers and want to compare it for a value in a cell. Lets say i want a number to be generated between 1 and 5 and repeat this process 10 times - criteria being number 3. Now i am looking to write a macro that should recalculate sheet 10 times (recalculate because i have used randbetween function to generate random numbers), but meanwhile calculating the sheet, if the random number comes to be 3, it should stop and report the instance.
Here is the code that i have written, there is problem with the macro until i compare values.
Note that Just to test the macro, i wanted to display the msg box. The random number is generated in cell B4 means B4 has formula =RANDBETWEEN(1,5).
Similarly C6 contains the times sheet to be recalculate and in cell C7 i want the instance when criteria is meet.
Thanks alot in advace!!
Faseeh
I hope this has not been answered on this forums, I tried to search for a solution but have reached this far (see below code).
The problem: I have sheet where i want to simulate a certain process. I generate random numbers and want to compare it for a value in a cell. Lets say i want a number to be generated between 1 and 5 and repeat this process 10 times - criteria being number 3. Now i am looking to write a macro that should recalculate sheet 10 times (recalculate because i have used randbetween function to generate random numbers), but meanwhile calculating the sheet, if the random number comes to be 3, it should stop and report the instance.
Here is the code that i have written, there is problem with the macro until i compare values.
Code:
Sub Test()
Dim n As Integer
n = ActiveSheet.Range("C6").Value
For i = 1 To n
ActiveSheet.Calculate
If Range("B4").Value = 0 Then MsgBox "Incorrect Value"
Exit Sub
Next i
End Sub
Note that Just to test the macro, i wanted to display the msg box. The random number is generated in cell B4 means B4 has formula =RANDBETWEEN(1,5).
Similarly C6 contains the times sheet to be recalculate and in cell C7 i want the instance when criteria is meet.
Thanks alot in advace!!
Faseeh
Last edited: