Good Morning
I would like to know how to use a timer in my macro.
ex (I have a start button, when started it needs to create a random number in a text box every 00:05 seconds)
I can make it create the numbers, but I can not get it to update the text box automatically at the given time.
I want to have to click only once on start and the macro generates numbers until I click stop
If someone can help me, I thank them
You can use a simple time delay. For example:
tm = TimerDo DoEventsLoop Until (Timer - tm) >= 5 'exit after 5 sec
I must be wrong in something very simple, I tried to fit the example in my code but I did not get any results
Private Sub CommandButton1_start_Click() While OptionButton1 = True
TextBox2.Value = TextBox2.Value - 1 Dim i As Long
Do i = Int(Rnd() * 9999) + 1 If i < 9999 And i > 1 Then TextBox1.Value = i:
Dim timer tm = timer Do DoEvents Loop Until (timer - tm) >= 5 'exit after 5 secIf TextBox2.Value = 0 Then MsgBox "You have reached the end" Unload Me End If Exit Sub Loop WendEnd Sub
Timer - is standard function, change Dim timer to Dim tm&