I'm looking to have a couple of dates stamped onto the spreadsheet on opening.
My current script is as follows:
Private Sub Workbook_Open()
'Automate start time on opening
With Worksheets("Time Recording Estimate")
If IsEmpty(.Range("B4")) Then .Range("B4").Value = "Start"
End With
End Sub
I now wish to also add a stamp for the last Sunday, hoping it can look something like the following:
Private Sub Workbook_Open()
'Automate start time on opening
With Worksheets("Time Recording Estimate")
If IsEmpty(.Range("B4")) Then
.Range("B4").Value = "Start"
.Range("V3").Value = Now() - Weekday(Now()) + 1
End With
End Sub
I'm not sure which part of the formula is wrong and is failing to go through.
Much appreciated for any assistance offered.
Looks like your code is missing an
End If:Once I added that (and changed the worksheet name to one that I actually have), it ran properly: if cell
B4is empty then then it puts "Start" in cellB4and Sunday's date (today in this case, since it's Sunday) in cellV3.I'd suggest that you [always] add this line to the top of any module:
This will "force" proper declaration & usage of variables, objects, properties, etc, and will save you a lot of headaches in the future.
Also, you should compile the code, so you can see where problem lie. Here is a quick overview of the process.