Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default 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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Automatically run a choice of macros based on cell selection

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
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically filling a cell from a worksheet based on a selection Pbrent Excel Worksheet Functions 2 May 14th 10 03:39 PM
Force entry into cell, based on validation selection in adjacent cell Richhall[_2_] Excel Worksheet Functions 3 June 18th 09 10:28 AM
Selecting a cell entry based on cell validation selection Brutalius Excel Worksheet Functions 2 December 17th 08 03:44 AM
limit cell list selection based on the selection of another list lorraine Excel Worksheet Functions 2 December 14th 04 08:17 PM
Excel data entry: choice of control for selection David Powell Excel Programming 3 August 13th 03 06:08 PM


All times are GMT +1. The time now is 06:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"