Exit Sub if cell value = result of formula

Phoenix333

New Member
Joined
Sep 28, 2010
Messages
26
I have a scheduled event to open a workbook at a set time each day. In the workbook, I have a macro programmed to run on opening [Auto_Open]. The last part of the macro saves then also does a save as, adds today's date to the filename and removes the macro so the new worksheet can be opened and viewed by others while leaving my template intact.
The problem is, I have occasion to open the template and when I do, I have to escape out of the macro to prevent it from running. Not a huge deal, but annoying.
So I thought of putting in code prior to calling the different steps of the macro that will check the value of a cell and if the value is equal to the result of the formula "=today()" then don't run the macro, but if it's not, then run it.

It's not working and since I'm not a macro expert (I get most of the code I use online and modify it to meet my needs), I'd really love some help.

Here's the code I currently have:

If ActiveSheet.Range("W2").Value = "=Today()" _
Then Exit Sub Else...

Part of the macro that runs adds the formula =today() to cell W2, then performs a copy--paste special so it doesn't change from day to day.

I want the beginning of the macro to look at the value in W2 and if the value is equal to what =today() would be, then I don't want the macro to run. So, for example, the report already ran today, meaning the value in W2 is 5/13/2011. If I open the report again today, then the macro wouldn't run because the value matches today's date.

Let me know if anyone has any suggestions.
Thanks in advance for any assistance.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
I think you just need to use the date() function

Code:
If ActiveSheet.Range("W2") = date() Then 
    exit sub
Else
    ActiveSheet.Range("W2") = date()
End if
Although you might want to put the update to the date at the very end of the macro's run.
Plus side, time stamp is only applied if the code executes successfully.
Down side, you need to be sure to apply it at every possible succesful execution exit point.
 
Upvote 0
This forum so needs a love smiley. You guys are fantastic! So simple...
Thanks you all so much, it worked and you were so fast to reply:biggrin:
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,853
Members
452,948
Latest member
UsmanAli786

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