Excel VBA - running a different routine based on value of cell

K

kimt

Great wise ones!

I need to run a different macro based on the value of (A1).

Example: If (A1)=1, then run macro "test", If (A1)=2, then run macr
"complete".

Thanks in advanc
 
D

dcronje

Here is simple method that could work:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$A$1" Then
Application.EnableEvents = False
If Target.Value = 1 Then
Call test
ElseIf Target.Value = 2 Then
Call complete
End If
Application.EnableEvents = True
End If

End Su
 
P

Peter Atherton

I need to run a different macro based on the value of (A1).

Example: If (A1)=1, then run macro "test", If (A1)=2, then run macro
"complete".

One way; copy these into a module and assign CallProcs to
a command button on your sheet.

Sub CallProcs()
If Range("A1") = 1 Then
Call Tested
Else: Call Complete
End If
End Sub

Private Sub Test()
MsgBox "Your value is being tested"
End Sub

Private Sub Complete()
MsgBox "The routine is complete"
End Sub

Regards
Peter
 
Top