Start & Stop The VBA Code Using Command Buttons

Being_Scorpio

New Member
Joined
Jan 6, 2024
Messages
4
Office Version
  1. 2021
Platform
  1. Windows
Hello Friends!!!
I am new to VBA Coding. I want to make a program in VBA Excel that has two command buttons. The first button executes the code and if I press the second button, I want the code in execution to be broken. The problem is that when I press the first button to execute the code, i cannot be able to click the second button until the code execution is completed. Please Help!!
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
welcome to the forum, the key thing you need to add is the "doevents" function. try this code on a blank workbook with a start button and a stop buttom calliing the two macros:
VBA Code:
Public stopflag As Boolean
Sub start()
stopflag = False
For i = 1 To 10000
Range("a1") = Range("a1") + 1
DoEvents
If stopflag Then Exit Sub
Next i
'
End Sub

Sub stoprun()
stopflag = True
End Sub
 
Upvote 1
Solution
Thank you for your help. It is working but when I press the Stoprun button a pop-up message appears saying out of memory.
 
Upvote 0
Have you tried the code exactly as I posted it in a new blank workbook?, because there isn't anything in that code that should cause an out of memory error. If you have tried this with your code can you post your code. When posting code please use Code tags to format the code ( like the code I posted) This is easily done by clicking on the VBA button above and then pasting your code.
Also where have you copied the code to?? It should be in a standard module not in the worksheet code
 
Upvote 1
Have you tried the code exactly as I posted it in a new blank workbook?, because there isn't anything in that code that should cause an out of memory error. If you have tried this with your code can you post your code. When posting code please use Code tags to format the code ( like the code I posted) This is easily done by clicking on the VBA button above and then pasting your code.
Also where have you copied the code to?? It should be in a standard module not in the worksheet code
My issue has been solved for now. Thank you very much.
 
Upvote 0
I have created two search boxes for two tables in an Excel file. Whenever I use a filter formula for one table, the previous formula becomes invalid. Please help.

I have created two list of tables in one sheet and using two search boxes in second sheet.

My Formulas:
=FILTER(Officers_List,ISNUMBER(SEARCH($D$3,Name)),"Not Found")
=FILTER(Workers_List,ISNUMBER(SEARCH($L$3,Name)),"Not Found")
 
Upvote 0
You need to start a new thread for this question because is entirely different to your orginal question
 
Upvote 0

Forum statistics

Threads
1,223,157
Messages
6,170,420
Members
452,325
Latest member
BlahQz

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