IF Sstatement in macro

Corleone

Well-known Member
Joined
Feb 2, 2003
Messages
841
Office Version
  1. 365
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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,849
Members
449,051
Latest member
excelquestion515

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
Back
Top