Macro so you can go to sleep

Sunvisor

Board Regular
Joined
Oct 9, 2009
Messages
233
Is there a macro I can create so I can get some sleep in front of my computer. I have my back turned to the office and I think as long as my hand is on a mouse and scrolling is being done in excel, no questions will be raised. =P
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Sorry, this made me laugh so hard I had to give it a shot!

This macro will be hidden, so it can only be activated by typing the name of the macro into the Alt-F8 popup window. Or you can assign it to a button, but again, you'll have to manually type SleeperAgent into the Assign Macro dialog.

Code:
Option Explicit

Private Sub SleeperAgent()
Dim cnt As Long, Timer As String, ws As Worksheet, MyArr

cnt = Application.InputBox("How many times through?", "Loop Count", 200)
If cnt = False Then Exit Sub
On Error GoTo 0
MyArr = Array("00:00:01", "00:00:02", "00:00:03", "00:00:04")

Do
    For Each ws In Worksheets
        ws.Activate
        Timer = Int((3 - 1 + 1) * Rnd + 1) - 1    'random number between 1 and 3.
        Application.Wait (Now + TimeValue(MyArr(Timer)))
        ActiveWindow.SmallScroll Down:=Timer
        ActiveWindow.SmallScroll ToRight:=Timer
        Application.Wait (Now + TimeValue(MyArr(Timer)))
        Range("A1").Activate
        Randomize
    Next ws
    
    cnt = cnt - 1
    
Loop Until cnt = 0

Beep

End Sub

Hehe...shameless, dude, really shameless.
 
Sorry, this made me laugh so hard I had to give it a shot!

This macro will be hidden, so it can only be activated by typing the name of the macro into the Alt-F8 popup window. Or you can assign it to a button, but again, you'll have to manually type SleeperAgent into the Assign Macro dialog.

Code:
Option Explicit

Private Sub SleeperAgent()
Dim cnt As Long, Timer As String, ws As Worksheet, MyArr

cnt = Application.InputBox("How many times through?", "Loop Count", 200)
If cnt = False Then Exit Sub
On Error GoTo 0
MyArr = Array("00:00:01", "00:00:02", "00:00:03", "00:00:04")

Do
    For Each ws In Worksheets
        ws.Activate
        Timer = Int((3 - 1 + 1) * Rnd + 1) - 1    'random number between 1 and 3.
        Application.Wait (Now + TimeValue(MyArr(Timer)))
        ActiveWindow.SmallScroll Down:=Timer
        ActiveWindow.SmallScroll ToRight:=Timer
        Application.Wait (Now + TimeValue(MyArr(Timer)))
        Range("A1").Activate
        Randomize
    Next ws
    
    cnt = cnt - 1
    
Loop Until cnt = 0

Beep

End Sub

Hehe...shameless, dude, really shameless.

Hello jbeaucaire,

Seems to give me an error when I run it. No message just a red circle w/ an X the number "400" with the option to "ok" or "help" in the VBA editor.
 
Stepping through the code gives me a Run-time error '1004' on this line:

Code:
Range("A1").Activate

when it gets to the 2nd sheet. Works fine on the first sheet.
 
Hmm, odd. It cycles fine for me on Excel 2003.

NOTE: To break out of the sleep-scrolling, press ESC twice.
 
This was purely for fun and I'm sure there enough in that macro you can construct one for yourself to do what you want it to do in a loop.

Have fun...ZZZZZZzzzzzzzzzzzzz
 
Stepping through the code gives me a Run-time error '1004' on this line:

Code:
Range("A1").Activate
hi,
when it gets to the 2nd sheet. Works fine on the first sheet.
you must have your code put in a worksheetmodule
it tries to activate A1 on the sheet where the code resides while it is not active

solution:
put your code in a normal module or workbookmodule

kind regards,
Erik
 

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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