If cell meets condition then run macro

Swoootie

Board Regular
Joined
Jun 28, 2012
Messages
66
Hi all,

I have an IF statement where I want code in a different macro executed when a cell is populated with a specific value. My code thus far is below:

Sub RUNOPT()
Sheets("Main Page").Select
If Sheets("Main PAGE").Range("L15") = "A" Then Call RUNA
If Sheets("Main PAGE").Range("L15") = "B" Then Call RUNB
If Sheets("Main PAGE").Range("L15") = "C" Then Call RUNC
If Sheets("Main PAGE").Range("L15") = "D" Then Call RUND
End Sub

Is it possible to add such conditions to an IF statement. I'm not entirely sure what is going on.

Any help would be greatly appreciated.

Thanks
 

Some videos you may like

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Maybe like this

Code:
Sub RUNOPT()
Sheets("Main Page").Select
Select Case Range("L15").Value
    Case "A": Call RUNA
    Case "B": Call RUNB
    Case "C": Call RUNC
    Case "D": Call RUND
End Select
End Sub
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
Hi all,

I have an IF statement where I want code in a different macro executed when a cell is populated with a specific value. My code thus far is below:

Sub RUNOPT()
Sheets("Main Page").Select
If Sheets("Main PAGE").Range("L15") = "A" Then Call RUNA
If Sheets("Main PAGE").Range("L15") = "B" Then Call RUNB
If Sheets("Main PAGE").Range("L15") = "C" Then Call RUNC
If Sheets("Main PAGE").Range("L15") = "D" Then Call RUND
End Sub

Is it possible to add such conditions to an IF statement. I'm not entirely sure what is going on.

Any help would be greatly appreciated.

Thanks

Yes. Have you tried it?
 

Swoootie

Board Regular
Joined
Jun 28, 2012
Messages
66
Hi. Thanks for your responses. it doesnt seem to be doing anything at all though.
 

Swoootie

Board Regular
Joined
Jun 28, 2012
Messages
66
Apologies. I was referencing a module not the sub procedure. Now corrected.

Thanks for all your help. :)
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
Thanks for the feedback.
Regards, JLG
 

Watch MrExcel Video

Forum statistics

Threads
1,122,780
Messages
5,598,038
Members
414,205
Latest member
Tushark

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top