Macro Doesn't Run Automatically

matthewlouis

Active Member
Joined
Mar 28, 2014
Messages
374
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Several months ago, I had some help creating the following macro.

Sub clicky()
For t = 1 To 100
Application.Calculate
Range("J10").Value = Range("J10").Value + 1
If Range("F11").Value <= 0.8 Then Range("J12").Value = Range("J12").Value + 1
Debug.Print t & ":" & Range("F11")
MsgBox t
Next t
End Sub

The macro works well except for one thing. It doesn't run automatically. When I hit CTRL-Shift-C, I want it to run the macro automatically 100 times. However, I am having to hit the Esc button each time to run ONE simulation, or 100 times to complete it. Am I missing a line in the code? I circled back to the person who helped write this code but I never heard back from him . . . it's been 3 months . . . so I hope the moderators understand this isn't a re-post.

Thanks in advance!


Several months ago, I had some help
 
I give up, too :) Someone else did this code because I don't do VBA, strictly excel functions. Yes, I do have a lot of excel functions in the background that would need explaining . . . but, at this point, if I can't just fix the code to get automation, so be it, I'll just do it manually because displaying / uploading the whole thing and explaining it . . . pretty time consuming and I don;t want to waste your time any more than I have . . . I really appreciate your effort in helping me! Thanks so much.
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
@matthewlouis, haven't actually read all posts within this thread yet, but where do you store the individual results of your intended simulations?
It seems to me that each result will be overwritten by the next one and that the code as of your post #19 just give you one result: the result of the last iteration.
 
Upvote 0
@GWteB, the individual results are not stored . . . each simulation overrides the previous simulation, however, I thought the code was compiling and accumulationg each simulation with the + 1.
 
Upvote 0
Your code runs 100 times but if you don't store the results you end up with just the result of the last run.
 
Upvote 0
80.png
 
Upvote 0
The picture shows 300 simulations . . . 68 failed and 232 were successful. Every time a simulation is done, it is complied per the code in the Failures and Successful.

So even though it's overriding the previous calculation, it is still adding each one up. So, it is storing each one.
 
Upvote 0
So for my understanding, when your macro runs once (with its 100 iterations), that is considered to be just ONE simulation. Am I right?
 
Upvote 0
When my macro runs once, yes, it is one simulation.

Right now, I am having to run the macro with Ctrl-Shift-C, hit Esc, and then I have to click the Esc button 100 times to get 100 simulations.

What I am wanting is to run the macro with Ctrl-Shift-C, hit Esc, and it automatically runs and accumulates 100 simulations.

This is the code:

Sub clicky()
For t = 1 To 100
Application.Calculate
Range("J10").Value = Range("J10").Value + 1
If Range("k2").Value <= 0.8 Then Range("J12").Value = Range("J12").Value + 1
MsgBox t
Next t
End Sub
 
Upvote 0
The bold 300 seems to be J10.... So the macro running once corresponds to 100 simulations.
 
Upvote 0

Forum statistics

Threads
1,216,038
Messages
6,128,450
Members
449,453
Latest member
jayeshw

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