ESC key to exit loop??

nikko50

Board Regular
Joined
Mar 3, 2004
Messages
155
How do I include the option for the user to exit the below loop with the ESCAPE key?


Do While Not IsEmpty(Cells(i, 1))

div = Cells(i, 1)

lne = Cells(i, 2)

'Application.Wait Now + TimeValue("00:00:01")
Sleep 1000
SendKeys div
SendKeys "{ENTER}", True
SendKeys "{TAB}", True
SendKeys "{TAB}", True
SendKeys lne
SendKeys "{TAB}", True
SendKeys "{ENTER}", True

Sheets("Sheet1").Select
Range("A" & i & ":B" & i).Select

With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With

'InteriorColor = ActiveCell.Interior.ColorIndex

Call SetCursorClickRight(Right_X, Right_Y)
'Application.Wait Now + TimeValue("00:00:01")
Call SetCursorClickLeft(Left_X, Left_Y)



i = i + 1
num = num + 1
Loop
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
You can use API GetAsyncKeyState.

Code:
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Code:
Do 
'your stuff

  DoEvents
  If GetAsyncKeyState(vbKeyEscape) Then 'cancel on Esc
  Exit Do
  End If

Loop
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,479
Members
448,967
Latest member
visheshkotha

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