Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
brettopp
 
Posts: n/a
Default How do I execute a macro based on the value of a cell in Excel?

For example, if cell A1=1, I want to run Macro1 once. If cell A1=2, I want
to run Macro2 once. If cell A1=3, do nothing.

I am familiar with Excel If/Then statements, so to my thinking, it would
look something like:

IF(A1=1,Run Macro1,IF(A1=2,Run Macro2,""))

I just don't know what the command is to "Run" the macro.
  #2   Report Post  
paul
 
Posts: n/a
Default How do I execute a macro based on the value of a cell in Excel?

others will reply i am sure with code.However you need to decide wether the
macro runs automatically of a worksheet change event so every time cell a1 is
changed(or any cell for that matter ) the macro would run.Alternatively you
could have a button to run the macro or just from the menu toolsmacrorun
macro
--
paul
remove nospam for email addy!



"brettopp" wrote:

For example, if cell A1=1, I want to run Macro1 once. If cell A1=2, I want
to run Macro2 once. If cell A1=3, do nothing.

I am familiar with Excel If/Then statements, so to my thinking, it would
look something like:

IF(A1=1,Run Macro1,IF(A1=2,Run Macro2,""))

I just don't know what the command is to "Run" the macro.

  #3   Report Post  
Norman Jones
 
Posts: n/a
Default How do I execute a macro based on the value of a cell in Excel?

Hi Brettop,

Try:
'===============
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("A1")) Is Nothing Then
Select Case Range("A1").Value
Case 1
macro1
Case 2
macro2
End Select
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.
*******************************************


---
Regards,
Norman



"brettopp" wrote in message
...
For example, if cell A1=1, I want to run Macro1 once. If cell A1=2, I
want
to run Macro2 once. If cell A1=3, do nothing.

I am familiar with Excel If/Then statements, so to my thinking, it would
look something like:

IF(A1=1,Run Macro1,IF(A1=2,Run Macro2,""))

I just don't know what the command is to "Run" the macro.



  #4   Report Post  
brettopp
 
Posts: n/a
Default How do I execute a macro based on the value of a cell in Excel

Thank you, Norman. This worked perfectly. It was exactly what I needed!

Brett


"Norman Jones" wrote:

Hi Brettop,

Try:
'===============
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("A1")) Is Nothing Then
Select Case Range("A1").Value
Case 1
macro1
Case 2
macro2
End Select
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.
*******************************************


---
Regards,
Norman



"brettopp" wrote in message
...
For example, if cell A1=1, I want to run Macro1 once. If cell A1=2, I
want
to run Macro2 once. If cell A1=3, do nothing.

I am familiar with Excel If/Then statements, so to my thinking, it would
look something like:

IF(A1=1,Run Macro1,IF(A1=2,Run Macro2,""))

I just don't know what the command is to "Run" the macro.




  #5   Report Post  
Ltat42a
 
Posts: n/a
Default How do I execute a macro based on the value of a cell in Excel?


brettopp Wrote:
Thank you, Norman. This worked perfectly. It was exactly what I
needed!

Brett


"Norman Jones" wrote:

Hi Brettop,

Try:
'===============
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("A1")) Is Nothing Then
Select Case Range("A1").Value
Case 1
macro1
Case 2
macro2
End Select
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.
*******************************************


---
Regards,
Norman



"brettopp" wrote in message
...
For example, if cell A1=1, I want to run Macro1 once. If cell

A1=2, I
want
to run Macro2 once. If cell A1=3, do nothing.

I am familiar with Excel If/Then statements, so to my thinking, it

would
look something like:

IF(A1=1,Run Macro1,IF(A1=2,Run Macro2,""))

I just don't know what the command is to "Run" the macro.






I have a spreadsheet that I use an image to run a macro. If I were to
use the above script to run my macros, how do I do this. Where does
this script go?
My choices for input would "A" - "B" or "C".

Thanx


--
Ltat42a
------------------------------------------------------------------------
Ltat42a's Profile: http://www.excelforum.com/member.php...o&userid=24735
View this thread: http://www.excelforum.com/showthread...hreadid=478509



  #6   Report Post  
Norman Jones
 
Posts: n/a
Default How do I execute a macro based on the value of a cell in Excel?

Hi Ltat42a,

I have a spreadsheet that I use an image to run a macro. If I were to
use the above script to run my macros, how do I do this. Where does
this script go?
My choices for input would "A" - "B" or "C".


Paste the following code into a standard module - not a worksheet module or
the ThisWorkbook module:

'===========
Sub aTester()
Select Case Range("A1").Value ' <<===== CHANGE
Case "A"
Macro1 '<<===== CHANGE
Case "B"
Macro2 '<<===== CHANGE
Case "C"
Macro3 '<<===== CHANGE
End Select
End Sub
'===========

Assign this macro to the image.

---
Regards,
Norman


  #7   Report Post  
Ltat42a
 
Posts: n/a
Default How do I execute a macro based on the value of a cell in Excel?


Norman Jones Wrote:
Hi Ltat42a,

I have a spreadsheet that I use an image to run a macro. If I were

to
use the above script to run my macros, how do I do this. Where does
this script go?
My choices for input would "A" - "B" or "C".


Paste the following code into a standard module - not a worksheet
module or
the ThisWorkbook module:

'===========
Sub aTester()
Select Case Range("A1").Value ' <<===== CHANGE
Case "A"
Macro1 '<<===== CHANGE
Case "B"
Macro2 '<<===== CHANGE
Case "C"
Macro3 '<<===== CHANGE
End Select
End Sub
'===========

Assign this macro to the image.

---
Regards,
Norman



Oooppps. I should have explained better. I want to get rid of the
images I use to run the macros. When a user inserts an "A" into a
particular cell, it will run the "A" macro that I created, when someone
enters "B", it runs the "B" macro...etc...etc...


Sorry...


--
Ltat42a
------------------------------------------------------------------------
Ltat42a's Profile: http://www.excelforum.com/member.php...o&userid=24735
View this thread: http://www.excelforum.com/showthread...hreadid=478509

  #8   Report Post  
Gary''s Student
 
Posts: n/a
Default How do I execute a macro based on the value of a cell in Excel?

You need a worksheet change event macro. See:

http://www.mvps.org/dmcritchie/excel/event.htm
--
Gary''s Student


"brettopp" wrote:

For example, if cell A1=1, I want to run Macro1 once. If cell A1=2, I want
to run Macro2 once. If cell A1=3, do nothing.

I am familiar with Excel If/Then statements, so to my thinking, it would
look something like:

IF(A1=1,Run Macro1,IF(A1=2,Run Macro2,""))

I just don't know what the command is to "Run" the macro.

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
How do I change fill color in excel based on data in the cell Jason Southco Excel Worksheet Functions 1 September 29th 05 04:56 PM
Cell color based upon cell value My View Excel Discussion (Misc queries) 11 July 6th 05 03:59 AM
Possible Lookup Table Karen Excel Worksheet Functions 5 June 8th 05 09:43 PM
enter a new value into a cell using macro in excel cath Excel Discussion (Misc queries) 2 April 12th 05 11:32 PM
Excel formulas based upon the color shading of a cell? DGBG Excel Worksheet Functions 1 April 12th 05 10:35 PM


All times are GMT +1. The time now is 10:07 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"