View Single Post
  #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.