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-
 

Some videos you may like

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

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
75,767
Office Version
365
Platform
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
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,862
Messages
5,513,840
Members
408,973
Latest member
TDotHanny

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top