# Getting bored Try this



## prajul89 (Aug 12, 2011)

```
Sub test()
On Error Resume Next
Application.StatusBar = Application.WorksheetFunction.RandBetween(1, 1000000000)
    Cells.Interior.Color = Application.WorksheetFunction.RandBetween(1, 1000000000)
    Application.OnTime Now, "test"
End Sub
```

Remember this macro will run continuously. to stop it Break it by pressing Ctrl+Break.


----------



## kgkev (Aug 15, 2011)

similar idea to this one.


```
Sub playing()
With Cells
    .Interior.ColorIndex = xlNone
    .ColumnWidth = 0.75
    .RowHeight = 6
End With
ActiveWindow.Zoom = 85
ActiveWindow.Zoom = 70


rght = 1
dwn = 1
lft = 2
up = 2
Range("da70").Select

Selection.Interior.ColorIndex = 1

rghttest = 0
dwntest = 0
lfttest = 0
uptest = 0


Do Until rght > 100
    Do Until rghttest = rght
        rghttest = rghttest + 1
        Selection.Offset(0, 1).Select
        Selection.Interior.ColorIndex = Int((55 - 1 + 1) * Rnd + 1)
    Loop

    rght = rght + 2
    rghttest = 0

    Do Until dwntest = dwn
        dwntest = dwntest + 1
        Selection.Offset(1, 0).Select
        Selection.Interior.ColorIndex = Int((55 - 1 + 1) * Rnd + 1)
    Loop

    dwntest = 0
    dwn = dwn + 2

    Do Until lfttest = lft
        lfttest = lfttest + 1
        Selection.Offset(0, -1).Select
       Selection.Interior.ColorIndex = Int((55 - 1 + 1) * Rnd + 1)
    Loop

    lfttest = 0
    lft = lft + 2

    Do Until uptest = up
        uptest = uptest + 1
        Selection.Offset(-1, 0).Select
        Selection.Interior.ColorIndex = Int((55 - 1 + 1) * Rnd + 1)
    Loop

    uptest = 0
    up = up + 2

Loop

Selection.Interior.ColorIndex = 0

End Sub
```


----------



## steve case (Aug 18, 2011)

Doesn't do anything on my machine.  What's it supposed to do?


----------



## Michael M (Aug 19, 2011)

Steve
Are you using option explicit ??
If so, turn it off and rerun.

Reaaly, really, exciting....not !!


----------



## steve case (Aug 19, 2011)

Michael M said:


> Steve
> Are you using option explicit ??
> If so, turn it off and rerun.
> 
> Reaaly, really, exciting....not !!



I have no idea what "Option Explicit" is or how to turn it on or off.  
So I Googled "Option Explicit" and wound up  here:

http://www.actuarialoutpost.com/actuarial_discussion_forum/showthread.php?t=97489

and I clicked on the "[ ] require variable definition" button both ways and 
nothing happened on either trial.

So, I gather that the cells are supposed to blink nice random patterns of color
or some such and some how "option explicit off" allows  that to happen.

​


----------



## Michael M (Aug 19, 2011)

Option explicit appears as text in the line above your Sub, if you have it turned on.
Your description of the "nice random patterns" is spot on !!!


----------



## kgkev (Aug 19, 2011)

Declared my variables now.


```
Option Explicit

Sub playing()

Dim rght As Single
Dim dwn As Single
Dim lft As Single
Dim up As Single
Dim rghttest As Single
Dim dwntest As Single
Dim lfttest As Single
Dim uptest As Single


With Cells
    .Interior.ColorIndex = xlNone
    .ColumnWidth = 0.75
    .RowHeight = 6
End With
ActiveWindow.Zoom = 85
ActiveWindow.Zoom = 70


rght = 1
dwn = 1
lft = 2
up = 2
Range("da70").Select

Selection.Interior.ColorIndex = 1

rghttest = 0
dwntest = 0
lfttest = 0
uptest = 0


Do Until rght > 100
    Do Until rghttest = rght
        rghttest = rghttest + 1
        Selection.Offset(0, 1).Select
        Selection.Interior.ColorIndex = Int((55 - 1 + 1) * Rnd + 1)
    Loop

    rght = rght + 2
    rghttest = 0

    Do Until dwntest = dwn
        dwntest = dwntest + 1
        Selection.Offset(1, 0).Select
        Selection.Interior.ColorIndex = Int((55 - 1 + 1) * Rnd + 1)
    Loop

    dwntest = 0
    dwn = dwn + 2

    Do Until lfttest = lft
        lfttest = lfttest + 1
        Selection.Offset(0, -1).Select
       Selection.Interior.ColorIndex = Int((55 - 1 + 1) * Rnd + 1)
    Loop

    lfttest = 0
    lft = lft + 2

    Do Until uptest = up
        uptest = uptest + 1
        Selection.Offset(-1, 0).Select
        Selection.Interior.ColorIndex = Int((55 - 1 + 1) * Rnd + 1)
    Loop

    uptest = 0
    up = up + 2

Loop

Selection.Interior.ColorIndex = 0

End Sub
```


----------



## steve case (Aug 19, 2011)

Michael M said:


> Option explicit appears as text in the line above your Sub, if you have it turned on.
> 
> Your description of the "nice random patterns" is spot on !!!


I do love this site, and this little topic is realy trivial, 

*B U T*

so far I've been told that I need to turn off Option Explicit and I'm also told  
what I should see if I have it turned on or off, but there hasn't been any 
instructions forthcoming as to exactly how to, key stroke by key stroke, turn 
it on or off.  

*(-:*




​


----------



## steve case (Aug 19, 2011)

kgkev said:


> Declared my variables now.


I did get yours to work,  cute.  


​


----------



## kgkev (Aug 19, 2011)

Option explicit either allows or disallows the use of undefined variables.

The first line of my code

"Option Explicit"

This turns it on in effect.


There is no user selectable option.



To get the code to work.

0.  I would suggest closing all other work books down - Don't want this to run on your proper work books!!!

1. Open a new Book.

2. Right Click "Sheet 1"

3. Click View Code

4. In Project viewer your should see VBAProject("Book 1")

5. Right click > INSERT > MODULE

6.Module1 will now be present.

7.  Paste the code into this module

"From OPTION EXPLICIT ..... END SUB"

8.Close VBA

9Go to your Macro menu  (depend which version you are using)

10. Run the macro called PLAYING


----------



## Michael M (Aug 19, 2011)

Steve
IF you paste the code into your VBA editor AND the first line is "Option Explicit" simply delete it.
If you want to turn it off for future "pastes", which is ill advised.
Open the VBA editor / tools / Options / Editor
and Check the "Require Variable Declaration" checkbox


----------



## kgkev (Aug 19, 2011)

```
Sub test()
On Error Resume Next
Count = 0
Do
Count = Count + 1
Application.StatusBar = Application.WorksheetFunction.RandBetween(1, 1000000000)
Cells.Interior.Color = Application.WorksheetFunction.RandBetween(1, 1000000000)
Loop Until Count = 100
    
End Sub
```

I see what you mean - I had the same problem with the first code.

If you put a loop on and change the 

"loop until Count" to a big number I think it has the same effect as the Original


----------



## andiemac (Aug 19, 2011)

Steve,

I think the idea of "turning on or off" Option Explicit is a bit misleading.  Simply deleting the line at the top of the of your code screen (the Project Editor) that says "Option Explicit" will turn off or make it not apply to the code you are trying to run.

There is a way to apply this to all future workbooks, but I would suggest that whatever options you have that work for you not be altered with out a good understanding of what the impact would be.  That said, you can set you options to always include Option Explicit by opening a VBA/Project Editor window, then choosing Options from the tools menu (not the Options menu when looking at a spreadsheet).  On the Editor Tab, make sure there is a check in the radio box for "Require Variable Declaration".  If the box is not checked, then you would have to type it in when you want to use it.


----------



## tweedle (Aug 19, 2011)

kgkev said:


> Don't want this to run on your proper work books!!!


 
I'll attest to that ... as I restore my prod project plan...


----------

