IF Sstatement in macro

Corleone

Well-known Member
Joined
Feb 2, 2003
Messages
721
I have a spreadsheet with 2 macros attached to it

1 - to run at the start of the week

the other - to run at the end of the week.

I would like to put some code on each of them which prevents the user
from running them in the wrong sequence.

eg - If CELL A10 contains "in progress" then I would like the 1st macro
to be disabled.

if CELL A10 contains "Closed" then then 2nd macro needs to be disabled

any ideas appreciated

thanks
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,456
It would be helpful to see the code in these routines, but maybe this is enough to get you going.
(Replace Sheet1 with whatever the sheet's name is...)

In your first routine, begin it with:
If Sheets("Sheet1").[A10].Value = "in progress" Then Exit Sub
Or with:
If Sheets("Sheet1").[A10].Value <> "Closed" Then
the rest of your code ...

In the second routine, begin it with:
If Sheets("Sheet1").[A10].Value = "Closed" Then Exit Sub
Or with:
If Sheets("Sheet1").[A10].Value <> "in progress" Then
the rest of your code...


Then at some point, you'll want to make sure that A10 has the value either "in progress" or "Closed" in it. Most likely that would probably come from the end of these routines...

at the end of rourine 1:
Sheets("Sheet1").[A10].Value = "in progress"

at the end of the second...
Sheets("Sheet1").[A10].Value = "Closed"

but without seeing the code these are only guesses.

Another idea would be to have the current date in the workbook somewhere, and test for the days of the week that you want either of these routines to run on... or not...

Hope it helps,
Dan
 

Forum statistics

Threads
1,148,219
Messages
5,745,446
Members
423,952
Latest member
EduardoM

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