Require Macro order

austin350s10

Active Member
Joined
Jul 30, 2010
Messages
321
I'm working on a workbook that has 2 different buttons each with a separate macro assigned to them.

PROBLEM: The 2 buttons are supposed to be in series. Meaning in order for the macros to work properly the use has to click the first button then the second one.

QUESTION: Is there a way I can add code to the macros that will force the user to click the first button before they click the second button. If for some reason they click the second button first I would love it if an error message could pop up letting the user know why they can do that.

Thanks,

-Austin-
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Weaver

Well-known Member
Joined
Sep 10, 2008
Messages
5,196
Does something else have to happen between the 2 buttons being clicked? I'm assuming so, otherwise you could just combine the two macros.

Maybe you could get button 1 to write to a cell somewhere and then button 2 doesn't work if there's no value in this cell?

Or you could even change the text on the buttons in some way that indicates which one to press next and use this as a criteria?

HTH
 

PA HS Teacher

Well-known Member
Joined
Jul 17, 2004
Messages
2,838
How about:

<font face=Courier New><SPAN style="color:#00007F">Public</SPAN> AllowButton2 <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN><br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> CommandButton1_Click()<br>   MsgBox "Button 1"<br>   AllowButton2 = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> CommandButton2_Click()<br>   <SPAN style="color:#00007F">If</SPAN> AllowButton2 <SPAN style="color:#00007F">Then</SPAN><br>      MsgBox "Button 2"<br>      AllowButton2 = <SPAN style="color:#00007F">False</SPAN> <SPAN style="color:#007F00">' If you want to force the use pressing of 1 first again.</SPAN><br>   <SPAN style="color:#00007F">Else</SPAN><br>      MsgBox "Sorry, You have to press button1 before you can press button2"<br>   <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,351
Office Version
  1. 365
Platform
  1. Windows
Why not either hide or disable the 2nd button?

Then have code that shows it or enables it once the code of the 1st button has completed.

You could even disable/hide the 1st button if you fancied.
 

bjurney

Active Member
Joined
Aug 24, 2009
Messages
320
To expand on Nories solution, the following code would enable the one button while disabling the other

Code:
Private Sub CommandButton1_Click()
CommandButton2.Enabled = True
CommandButton1.Enabled = False
End Sub

Code:
Private Sub CommandButton2_Click()
CommandButton2.Enabled = False
CommandButton1.Enabled = True
End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,113
Messages
5,857,453
Members
431,880
Latest member
kar2rost

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
Top