how to stop this loop - vba

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
I ran the code below forgetting to add x=x+1 and excel displayed the message box and no matter what I do, the msgbox wont go and everything got frozen. I had to go to task manager and end the process. Any better way to stop that without losing the code. Thank you

Code:
Sub mywhile()
Dim x As Integer
Do While x < 6
    MsgBox "hi"
Loop
End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi
I ran the code below forgetting to add x=x+1 and excel displayed the message box and no matter what I do, the msgbox wont go and everything got frozen. I had to go to task manager and end the process. Any better way to stop that without losing the code.
The short answer is no.
 
Upvote 0
What is your objective?

Why would you want a message box to keep popping up saying "Hi" over and over?
 
Upvote 0
It does work, but, as you mentioned, I didn't consider the newer keyboards....my laptop doesn't have it !!!
But for those that don't have BREAK, you could use

Ctrl + Fn + F11

Hate to think what it would be on a Mac.
 
Upvote 0
It does work, but, as you mentioned, I didn't consider the newer keyboards....my laptop doesn't have it !!!
But for those that don't have BREAK, you could use

Ctrl + Fn + F11

Hate to think what it would be on a Mac.

I am not sure what you think that key combination was supposed to do, but on my laptop, it made me log into my computer again and I was right back at the "stalled" MessageBox.
 
Last edited:
Upvote 0
Sorry Rick but it works for me.....but I do have a pretty old Dell laptop !!
 
Upvote 0

Forum statistics

Threads
1,223,991
Messages
6,175,820
Members
452,672
Latest member
missbanana

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