I am trying to setup a Date/Time check for a workbook.
I am not getting any errors in my logic however, I just don't think this is correct.
In each If statement, I placed a check to see if the statement "If cDate" was working correct and not getting what I think I should.
I am getting the "Date Changed" value for each statement
Hope someone can validate my logic, and help correct.
Logic & Mini Sheet below:
I am not getting any errors in my logic however, I just don't think this is correct.
In each If statement, I placed a check to see if the statement "If cDate" was working correct and not getting what I think I should.
I am getting the "Date Changed" value for each statement
Hope someone can validate my logic, and help correct.
Logic & Mini Sheet below:
VBA Code:
Option Explicit
Sub ResetRow30()
Rows("30:30").ClearContents
End Sub
Sub TimeCheck()
Application.ScreenUpdating = True
Dim Rng As Range
'CurrDayR
Set Rng = Sheets(1).Range("$D$26")
If CDate(Format(Now, "d-mmm-yy hh:mm:ss")) > Rng Then
Sheets(1).Range("$D$2") = "=(TODAY()-1)+TIMEVALUE(""07:00:00"")"
Sheets(1).Range("CurrDayR").Calculate
Sheets(1).Range("$D$30").Value = "Date Changed"
Set Rng = Nothing
End If
'CurrDayV
Set Rng = Sheets(1).Range("$F$3")
If CDate(Format(Now, "d-mmm-yy hh:mm:ss")) > Rng Then
Sheets(1).Range("CurrDayV").Calculate
Sheets(1).Range("$F$30").Value = "Date Changed"
Set Rng = Nothing
End If
'PrevDayR
Set Rng = Sheets(1).Range("$H$26")
If CDate(Format(Now, "d-mmm-yy hh:mm:ss")) - 1 > Rng Then
Sheets(1).Range("$H$2") = "=(TODAY()-2)+TIMEVALUE(""07:00:00"")"
Sheets(1).Range("PrevDayR").Calculate
Sheets(1).Range("$H$30").Value = "Date Changed"
Set Rng = Nothing
End If
'PrevDayV
Set Rng = Sheets(1).Range("$J$3")
If CDate(Format(Now, "d-mmm-yy hh:mm:ss")) - 1 > Rng Then
Sheets(1).Range("PrevDayV").Calculate
Sheets(1).Range("$J$30").Value = "Date Changed"
Set Rng = Nothing
End If
'CurrMonthV
Set Rng = Sheets(1).Range("$L$3")
If CDate(Format(Now, "d-mmm-yy hh:mm:ss")) + 1 > Rng Then
Sheets(1).Range("$L$2") = "=EOMONTH(TODAY(),-1)+1+ TIMEVALUE(""07:00:00"")"
Sheets(1).Range("$L$3") = "=NOW()"
Sheets(1).Range("CurrMonthV").Calculate
Sheets(1).Range("$L$30").Value = "Date Changed"
Set Rng = Nothing
End If
'PrevMonthV
Set Rng = Sheets(1).Range("$N$3")
If CDate(Format(Now, "d-mmm-yy hh:mm:ss")) + 1 > Rng Then
Sheets(1).Range("$N$2") = "=EOMONTH(TODAY(),-2)+1+ TIMEVALUE(""07:00:00"")"
Sheets(1).Range("$N$3") = "=EOMONTH(TODAY(),-1)+1+ TIMEVALUE(""07:00:00"")"
Sheets(1).Range("PrevMonthV").Calculate
Sheets(1).Range("$N$30").Value = "Date Changed"
Set Rng = Nothing
End If
Sheets(1).Range("TimeStamp") = "=Now()"
Application.ScreenUpdating = True
End Sub
Cell Formulas | ||
---|---|---|
Range | Formula | |
B2,L3,F3 | B2 | =NOW() |
F2,D2 | F2 | =(TODAY()-1)+TIMEVALUE("07:00:00") |
J2 | J2 | =TODAY()-3+1+TIMEVALUE("07:00:00") |
J3 | J3 | =TODAY()-2+1+TIMEVALUE("07:00:00") |
L2,N3 | L2 | =EOMONTH(TODAY(),-1)+1+ TIMEVALUE("07:00:00") |
N2 | N2 | =EOMONTH(TODAY(),-2)+1+ TIMEVALUE("07:00:00") |
D3:D26 | D3 | =$D2+TIME(1,0,0) |
H2 | H2 | =(TODAY()-2)+TIMEVALUE("07:00:00") |
H3:H26 | H3 | =$H2+TIME(1,0,0) |
Named Ranges | ||
---|---|---|
Name | Refers To | Cells |
CurrDayR | =TimeCheck!$D$2:$D$26 | D3 |
PrevDayR | =TimeCheck!$H$2:$H$26 | H3 |