ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Placing macros within the IF condition (https://www.excelbanter.com/excel-worksheet-functions/153229-placing-macros-within-if-condition.html)

sonia

Placing macros within the IF condition
 
Hi...

I would like to run the below condition in excel.

If value of column A=1 then run macro A
If value of column A=2 then run macro B
If value of column A=3 then run macro C

Please help..

Bye for now
Sonia

Bob Phillips

Placing macros within the IF condition
 
You cannot run a macro in an IF Function if that macro tries to modify the
sheet or cells in any way. If it is a function that returns a result then
that is okay, simply

=IF(A1=1,Function1, IF(A2=2,Function2, etc.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Sonia" wrote in message
...
Hi...

I would like to run the below condition in excel.

If value of column A=1 then run macro A
If value of column A=2 then run macro B
If value of column A=3 then run macro C

Please help..

Bye for now
Sonia




CLR

Placing macros within the IF condition
 
Perhaps this will do as you wish.........

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Address = "$A$1" Then
If Target.Value = 1 Then Call macroA
If Target.Value = 2 Then Call macroB
If Target.Value = 3 Then Call macroC
End If
End Sub

Vaya con Dios,
Chuck, CABGx3



"Sonia" wrote:

Hi...

I would like to run the below condition in excel.

If value of column A=1 then run macro A
If value of column A=2 then run macro B
If value of column A=3 then run macro C

Please help..

Bye for now
Sonia


sonia

Placing macros within the IF condition
 
The macro is not being used to modify the sheet. based on the value in Column
A the respective macro has to be run. ( the macro is to only open another
file ).
Please let me know which function I can use in the IF function to run the
macro.

"Bob Phillips" wrote:

You cannot run a macro in an IF Function if that macro tries to modify the
sheet or cells in any way. If it is a function that returns a result then
that is okay, simply

=IF(A1=1,Function1, IF(A2=2,Function2, etc.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Sonia" wrote in message
...
Hi...

I would like to run the below condition in excel.

If value of column A=1 then run macro A
If value of column A=2 then run macro B
If value of column A=3 then run macro C

Please help..

Bye for now
Sonia





Bob Phillips

Placing macros within the IF condition
 
As I said, if it is modifying the sheet or cells it cannot be called from a
worksheet function.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Sonia" wrote in message
...
The macro is not being used to modify the sheet. based on the value in
Column
A the respective macro has to be run. ( the macro is to only open another
file ).
Please let me know which function I can use in the IF function to run the
macro.

"Bob Phillips" wrote:

You cannot run a macro in an IF Function if that macro tries to modify
the
sheet or cells in any way. If it is a function that returns a result then
that is okay, simply

=IF(A1=1,Function1, IF(A2=2,Function2, etc.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

"Sonia" wrote in message
...
Hi...

I would like to run the below condition in excel.

If value of column A=1 then run macro A
If value of column A=2 then run macro B
If value of column A=3 then run macro C

Please help..

Bye for now
Sonia








All times are GMT +1. The time now is 02:55 AM.

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