ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Deactivate button macro if condition not met (https://www.excelbanter.com/excel-programming/437529-deactivate-button-macro-if-condition-not-met.html)

GBExcel via OfficeKB.com

Deactivate button macro if condition not met
 
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.

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200912/1


marcus[_3_]

Deactivate button macro if condition not met
 
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

GBExcel via OfficeKB.com

Deactivate button macro if condition not met
 
Thank you.

Will try it out.

Appreciate the help.

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200912/1


GBExcel via OfficeKB.com

Deactivate button macro if condition not met
 
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

--
Message posted via http://www.officekb.com



All times are GMT +1. The time now is 02:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com