# SIlly fun question?

#### countryfan_nt

##### Well-known Member
Hello Friends,

Here comes a crazy fun question.

I was wondering is there a macro where when it is run you would see numbers popping up one after another in cell B5. Numbers start from 100 to 0.

Thanks and All the best,
Nawaf

### Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Code:
``````Sub Numbers()
Dim i As Integer, waitTime As Variant

For i = 0 To 100
Range("B5").Value = i
waitTime = TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 1)
Application.Wait waitTime

Next i

MsgBox "Finished!"

End Sub``````

Nice code but........

It is running now but unless I want to kill xl I have to wait 100 seconds for it to stop!!

Yes, I know. I don't know any way around that off of the top of my head, though.

If you run that code without the Wait statement, it goes too fast to watch the numbers change and all you really see is the final result of 100.

Here are a couple ideas you can try.
(1) Using Krysty's Wait method...
Code:
``````Sub Numbers()
Dim i As Integer, waitTime As Variant
On Error GoTo Quit
For i = 0 To 100
If [B4] <> "" Then Exit For
Range("B5").Value = i
waitTime = TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 1)
Application.Wait waitTime
Next i
MsgBox "Finished!"
Quit:
Range("B5").Value = "Stopped"
End Sub``````
You can simply hit the ESC button to stop the code.

(2) With these 3 routines (and a second button for the "StopIt" routine) you can start the Numbers2 routine and then hit the button for the "StopIt" routine to make it stop.
Code:
``````Sub Numbers2()
If [B4] = "" Then
If [B5] < 100 Then
Application.OnTime Now + TimeSerial(0, 0, 1), "IncrementB5"
Else: MsgBox "Finished"
End If
End If
End Sub

Sub IncrementB5()
Range("B5").Value = Range("B5").Value + 1
Numbers2
End Sub

Sub StopIt()
[B4] = "Stop"
End Sub``````
The OnTime method will allow user interaction where as the Wait command won't.

Hope it helps.
Dan

Replies
4
Views
491
Replies
1
Views
330
Replies
0
Views
176
Replies
1
Views
161
Replies
20
Views
528

1,203,464
Messages
6,055,577
Members
444,799
Latest member
CraigCrowhurst

### 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?

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