How do I initiate a macro directly in a worksheet?

G

Guest

All you need is a Command Button. Click on "View/Toolbars/Control Toolbox.
You will see, among others, the Command Button icon. Click it and click on
the sheet where you want the button. When you double-click the button a
Macro will be set up for you to place your code in. If you right-click the
button and choose "Properties" you can change the Caption on it etc.
 
N

Norman Jones

Hi AMMPro,

Try:

'=============>>
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range

Set rng = Me.Range("A1") '<<==== CHANGE

If Not Intersect(Target, rng) Is Nothing Then
Call MyMacro
End If
End Sub
'<<=============

This is worksheet event code and should be pasted into the worksheets's code
module (not a standard module and not the workbook's ThisWorkbook module):

Right-click the worksheet's tab
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.
 

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