Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Automatically run a choice of macros based on cell selection
I need to run a macro based on whether cell P7 in a worksheet contains
value 1, 2 or 3. If cell contains value 1, would automatically run Macro1, if 2 would run Macro2, and if 3 then run Macro3. Can anyone tell me how to do this? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Automatically run a choice of macros based on cell selection
Select Case Range("P7")
Case 1 Call macro1 Case 2 Call macro2 Case 3 Call macro3 End Select End Sub Regards, Stefi €ť ezt Ă*rta: I need to run a macro based on whether cell P7 in a worksheet contains value 1, 2 or 3. If cell contains value 1, would automatically run Macro1, if 2 would run Macro2, and if 3 then run Macro3. Can anyone tell me how to do this? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Automatically run a choice of macros based on cell selection
Thanks Stefi
Will this automatically run if the cell value changes? I'm having difficulty getting it to work. Do I put the code in a normal module or the sheet code? Cheers Mike Stefi wrote: Select Case Range("P7") Case 1 Call macro1 Case 2 Call macro2 Case 3 Call macro3 End Select End Sub Regards, Stefi " ezt írta: I need to run a macro based on whether cell P7 in a worksheet contains value 1, 2 or 3. If cell contains value 1, would automatically run Macro1, if 2 would run Macro2, and if 3 then run Macro3. Can anyone tell me how to do this? |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Automatically run a choice of macros based on cell selection
Hi Mike,
Try this code in the sheet's code module... Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Not Intersect(Target, Range("P7")) Is Nothing Then Application.EnableEvents = False Select Case Range("P7") Case 1 Call macro1 Case 2 Call macro2 Case 3 Call macro3 End Select End If Application.EnableEvents = True End Sub Ken Johnson |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Automatically run a choice of macros based on cell selection
Hi Mike, Or, you might want to use the Worksheet_Change event instead of the Worksheet_SelectionChange event. I can't be sure since I don't know how the value of 1, 2 or 3 finds its way into P7. Ken Johnson |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Automatically run a choice of macros based on cell selection
Dear all - many thanks for your help and pointers, I got it to work fine in the end Mike Dave Peterson wrote: How does the cell change? If it's by the user typing, you can tie into the worksheet_change() event. If it's the result of a formula reevaluating, you could use the worksheet_calculate event. You can read more about events at: Chip Pearson's site: http://www.cpearson.com/excel/events.htm David McRitchie's site: http://www.mvps.org/dmcritchie/excel/event.htm If you're new to macros, you may want to read David McRitchie's intro at: http://www.mvps.org/dmcritchie/excel/getstarted.htm wrote: Thanks Stefi Will this automatically run if the cell value changes? I'm having difficulty getting it to work. Do I put the code in a normal module or the sheet code? Cheers Mike Stefi wrote: Select Case Range("P7") Case 1 Call macro1 Case 2 Call macro2 Case 3 Call macro3 End Select End Sub Regards, Stefi " ezt írta: I need to run a macro based on whether cell P7 in a worksheet contains value 1, 2 or 3. If cell contains value 1, would automatically run Macro1, if 2 would run Macro2, and if 3 then run Macro3. Can anyone tell me how to do this? -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Automatically filling a cell from a worksheet based on a selection | Excel Worksheet Functions | |||
Force entry into cell, based on validation selection in adjacent cell | Excel Worksheet Functions | |||
Selecting a cell entry based on cell validation selection | Excel Worksheet Functions | |||
limit cell list selection based on the selection of another list | Excel Worksheet Functions | |||
Excel data entry: choice of control for selection | Excel Programming |