Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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! |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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! |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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! |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|