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

  • Thread starter Thread starter kimt
  • Start date Start date
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
 
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
 
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
 
We'll give it a try, let you know how it goes, thanks for the quic
reply
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top