Deactivate button macro if condition not met

  • Thread starter GBExcel via OfficeKB.com
  • Start date
G

GBExcel via OfficeKB.com

Hi,

This is probably simple, but I am getting stuck with it.

I have a button with an attached macro. Cell A1 sets the permission that
allows the macro to run or not run as follows:

If Cell A1 is 1 the macro may continue to run.
If Cell A1 is 0 the macro may not run further and a popup alert should say,
"Stop! Button may not be used on this page."

I don't want to use data validation's conditional alert, because it would
cause a popup when the page opens and not when the user selects the button
mentioned above.

I'm trying If, Then, End if statements, but keep getting error messages.

Thank you for helping.
 
M

marcus

Hi

How about something like this;

If Range("A1").Value = 1 Then
'Run your code
Else
MsgBox "Stop! Button may not be used on this page."

Exit Sub

End Sub

Take care

Marcus
 
G

GBExcel via OfficeKB.com

Thank you Marcus,

I had to add in an End if, and it works.

If Range("A1").Value = "" Then
'Run your code

Else: MsgBox "Stop! Button may not be used on this page."

Exit Sub
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top