Choose a macro from within a macro

G

Guest

I need to write a macro which will choose one of two macros to run, based
upon the value in a single cell. The value in the single cell could be
either numeric or text.

In other words,

IF cell value = x, Application.Run"Macro1", ELSE Application.Run "Macro2".

But I just don't know how to write the proper code for this. Any clues?
 
G

Guest

Try this:-

Sub ordinate()
x = 6
If Cells(1, 1).Value = x Then
macro1
Else
macro2
End If
End Sub

Sub macro1()
MsgBox ("Macro1 running")
End Sub

Sub macro2()
MsgBox ("Macro2 running")
End Sub
 
G

Guest

Hey Mike,

Thanks for that!

Mike H said:
Try this:-

Sub ordinate()
x = 6
If Cells(1, 1).Value = x Then
macro1
Else
macro2
End If
End Sub

Sub macro1()
MsgBox ("Macro1 running")
End Sub

Sub macro2()
MsgBox ("Macro2 running")
End Sub
 

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

Top