Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
Attaching Macro to Cell instead of button?
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! |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
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! |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
Attaching Macro to Cell instead of button?
On 29 aug, 22:36, 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! You mean something like this ?? example macro xx reacts to changes on sheet 1 Sub xx() Range("c1").Value = Range("a1").Value * Range("b1").Value End Sub groeten. Hans (click on tab view code . in top line the following) Private Sub Worksheet_SelectionChange(ByVal Target As Range) xx End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Attaching an image to a cell | Excel Discussion (Misc queries) | |||
Need help with recording a macro, attaching a button | Excel Worksheet Functions | |||
Inserting a button into a cell and linking it to a macro | Excel Discussion (Misc queries) | |||
Attaching a macro to a VB button on a form | Excel Worksheet Functions | |||
Attaching a particular user defined function to cust button | Excel Discussion (Misc queries) |