I want a macro that will only allow it to run if specific cell/s are selected (or active) in the worksheet. For example: if cell J12 is selected the user can click on the menu bar to execute a macro. If cell J11 is selected the user can not execute any macros from the menu bar. The macros are executed from various menu bars in the workbook.
Thanks for your help.
Here's an example of a macro:
[vba]Sub Single1B()
Sheets("ScoreCard").Select
ActiveCell.Offset(1, 1).Select
Sheets("Symbols").Range("K16:M17").Copy ActiveCell
Sheets("ScoreCard").Select
ActiveCell.Offset(-1, -1).Select
End Sub[/vba]
Example of a menu bar:
[VBA]
Sub RunnerMakeOuts()
' This procedure creates a new temporary toolbar.
Dim ComBar As CommandBar, ComBarContrl As CommandBarControl
On Error GoTo ErrorHandler
' Create a new floating toolbar and make it visible.
On Error Resume Next
'Delete the toolbar if it already exists
CommandBars("Way Runners Make Outs").Delete
Set ComBar = CommandBars.Add(Name:="Way Runners Make Outs", Position:= _
msoBarFloating, Temporary:=True)
ComBar.Visible = True
' Create a button with text on the bar and set some properties.
Set ComBarC With ComBarContrl
.Caption = "CS 2B"
. .TooltipText = "Caught Stealing 2nd"
.
.BeginGroup = True
End With
Set ComBarC With ComBarContrl
.Caption = "CS 3B"
. .TooltipText = "Caught Stealing 3rd"
.
.BeginGroup = True
End With
Set ComBarC With ComBarContrl
.Caption = "CS Home"
. .TooltipText = "Caught Stealing Home"
.
.BeginGroup = True
End With
Set ComBarC With ComBarContrl
.Caption = "DP 1st"
. .TooltipText = "Double Play First"
.
.BeginGroup = True
End With
Set ComBarC With ComBarContrl
.Caption = "DP 2nd"
. .TooltipText = "Double Play Second"
.
.BeginGroup = True
End With
Set ComBarC With ComBarContrl
.Caption = "DP 3rd"
. .TooltipText = "Double Play Third"
.
.BeginGroup = True
.BeginGroup = True
End With
Set ComBarC With ComBarContrl
.Caption = "DP Home"
. .TooltipText = "Double Play Home"
.
.BeginGroup = True
End With
Exit Sub
ErrorHandler:
MsgBox "Error " & Err.Number & vbCr & Err.Description
Exit Sub
End Sub
[/VBA]