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

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
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
 
Upvote 0
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>
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,762
Members
449,048
Latest member
excelknuckles

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