View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
JLatham JLatham is offline
external usenet poster
 
Posts: 3,365
Default Attaching Macro to Cell instead of button?

Yes, use the worksheet's _Change() event handler. To get there, choose the
sheet, right-click the name tab and choose [View Code] from the list. Copy
the code below and modify as needed (specifically, change the address to the
cell with your list, and either put the code to execute within the If...End
If statements, or if code already exists in a public module, then just call
that Sub from within the If ... End If statements.

Note that this will run even if someone chooses the same item in the list
over and over again, not just another choice from the list.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$D$2" Then
'code to execute here
MsgBox "D2 changed"
End If
End Sub


"Satchmo2006" wrote:

Hello,
I have a cell that is a list. Instead of attaching a Macro to a button, I
would like it to run everytime a new selection from this list is selected. Is
this possible? If so, how?
Much thanks!