ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Choose a macro from within a macro (https://www.excelbanter.com/excel-programming/391631-choose-macro-within-macro.html)

Felicity Shagwell

Choose a macro from within a macro
 
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?

Mike H

Choose a macro from within a macro
 
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

"Felicity Shagwell" wrote:

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?


Felicity Shagwell

Choose a macro from within a macro
 
Hey Mike,

Thanks for that!

"Mike H" wrote:

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

"Felicity Shagwell" wrote:

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?



All times are GMT +1. The time now is 12:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com