Which is the most efficient way to do this?
Sub pvaSetWeek(Optional weekOffset As Long = 0)
Dim theDayToday As Long
theDayToday = Weekday(Now, vbMonday)
'Set start to Monday
Range("pvaStartDate") = Int(Now) - (theDayToday - 1) - (weekOffset * 7)
'Set end to Sunday
Range("pvaEndDate") = Int(Now) + (7 - theDayToday) - (weekOffset * 7)
End Sub
or
Sub pvaSetWeek(Optional weekOffset As Long = 0)
'Set start to Monday
Range("pvaStartDate") = Int(Now) - (Weekday(Now, vbMonday)- 1) - (weekOffset * 7)
'Set end to Sunday
Range("pvaEndDate") = Int(Now) + (7 - Weekday(Now, vbMonday)) - (weekOffset * 7)
End Sub
And why?
Edit to add: I usually go with the first way as it is easier to read/debug and obviously scales better if the same value needs used more than a couple of times, but where the value may only be used a few times I've often wondered if there is any penalty, however small, for doing things one way or another.