ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   One A day (https://www.excelbanter.com/excel-programming/341865-one-day.html)

Sandy

One A day
 
Hello Group
What should I add to my code to prevent it from being run once a day? Once
updated yesterdays date is in A2 of sheet1.
Thanks!

Tom Ogilvy

One A day
 
if worksheets("Sheet1").Range("A2").Value = Date - 1 then exit sub

--
Regards,
Tom Ogilvy


"Sandy" wrote in message
...
Hello Group
What should I add to my code to prevent it from being run once a day?

Once
updated yesterdays date is in A2 of sheet1.
Thanks!




K Dales[_2_]

One A day
 
Do you mean "prevent it from being run more than once a day?" Test the value
before the code changes it:
Sub RunMeOnceADay()
If Worksheeets("Sheet1").Range("A2").Value < Date()-1 Then
... code to run goes here
Worksheeets("Sheet1").Range("A2").Value = Date()-1 ' sets the date
in A2
End If
End Sub
If you really mean "once a day", when do you actually want/need the code to
run?
--
- K Dales


"Sandy" wrote:

Hello Group
What should I add to my code to prevent it from being run once a day? Once
updated yesterdays date is in A2 of sheet1.
Thanks!


Sandy

One A day
 
Thanks for the reply
The code is run manually, but we are having trouble with some operators
running it twice. As I said when the macro runs it changes the date in A2 to
yesterdays date and that is the check I was thinking of using to determine if
it had been already run. I guess a message box would be good too so I can
point out the error to the operator.
Thanks!

"K Dales" wrote:

Do you mean "prevent it from being run more than once a day?" Test the value
before the code changes it:
Sub RunMeOnceADay()
If Worksheeets("Sheet1").Range("A2").Value < Date()-1 Then
... code to run goes here
Worksheeets("Sheet1").Range("A2").Value = Date()-1 ' sets the date
in A2
End If
End Sub
If you really mean "once a day", when do you actually want/need the code to
run?
--
- K Dales


"Sandy" wrote:

Hello Group
What should I add to my code to prevent it from being run once a day? Once
updated yesterdays date is in A2 of sheet1.
Thanks!



All times are GMT +1. The time now is 10:14 AM.

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