please help! worksheet cycle macro

J

John S.

I am trying to cycle through some sheets, but when you hit Esc the
sheets cycle quickly until Esc is hit again. I want the macro to end
with just on press of Esc. Any help would be great, thanks.

I guess the main problem is interrupting the WAIT command and getting
passed the loop.


Sub CycleSheets()

Dim lIndex As Long

Application.EnableCancelKey = xlErrorHandler On Error GoTo ErrorCleanUp

Do Until test = True
For lIndex = 1 To 3
Sheets(lIndex).Select Application.Wait Time + TimeValue("00:00:02") Next
lIndex
Loop

ErrorCleanUp:
MsgBox "macro has been paused"
Exit Sub

End Sub
 
J

Jim Cone

Ctrl + Break is the only thing I can get to work.
--
Jim Cone
Portland, Oregon USA
http://www.contextures.com/excel-sort-addin.html

..
..
..

"John S." <[email protected]>
wrote in message
I am trying to cycle through some sheets, but when you hit Esc the
sheets cycle quickly until Esc is hit again. I want the macro to end
with just on press of Esc. Any help would be great, thanks.

I guess the main problem is interrupting the WAIT command and getting
passed the loop.


Sub CycleSheets()
Dim lIndex As Long
On Error GoTo ErrorCleanUp
Application.EnableCancelKey = xlErrorHandler

Do Until test = True
For lIndex = 1 To 3
Sheets(lIndex).Select Application.Wait Time + TimeValue("00:00:02")
Next 'lIndex
Loop

Exit Sub
ErrorCleanUp:
MsgBox "macro has been paused"
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top