Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I was wondering how I can get VBA in Excel'03 to recognize that if today is
Tuesday the 17th, or Firday the 20th, then the previous Monday must have been the 16th. Or is it is Friday April the 3rd then the previous Monday was March 30th? Escentially I am just looking for a way to have the VB identify what Day today is as well as the date and then calculate what the previous Monday was... Unless the current day happens to actually be Monday, in which case it just uses that date. Dim tDate, mDate As Date tDate = Format(Now(),"m/d/yyyy") tDay = Day(tDate) If tDay < "Monday" Then mDate = tDate - tDay The above code it what I toyed with but it has failed at every itteration I made of it. Thanks In Advance! |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Rob,
Try this tDate = Date - WeekDay(Date, 2) + 1 For future work you simply change the last 1 to a 2 for Tuesday etc. Mike "Rob" wrote: I was wondering how I can get VBA in Excel'03 to recognize that if today is Tuesday the 17th, or Firday the 20th, then the previous Monday must have been the 16th. Or is it is Friday April the 3rd then the previous Monday was March 30th? Escentially I am just looking for a way to have the VB identify what Day today is as well as the date and then calculate what the previous Monday was... Unless the current day happens to actually be Monday, in which case it just uses that date. Dim tDate, mDate As Date tDate = Format(Now(),"m/d/yyyy") tDay = Day(tDate) If tDay < "Monday" Then mDate = tDate - tDay The above code it what I toyed with but it has failed at every itteration I made of it. Thanks In Advance! |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
And including your formatting
tDate = Format(Date - WeekDay(Date, 2) + 1, "mm/dd/yyyy") Mike "Mike H" wrote: Rob, Try this tDate = Date - WeekDay(Date, 2) + 1 For future work you simply change the last 1 to a 2 for Tuesday etc. Mike "Rob" wrote: I was wondering how I can get VBA in Excel'03 to recognize that if today is Tuesday the 17th, or Firday the 20th, then the previous Monday must have been the 16th. Or is it is Friday April the 3rd then the previous Monday was March 30th? Escentially I am just looking for a way to have the VB identify what Day today is as well as the date and then calculate what the previous Monday was... Unless the current day happens to actually be Monday, in which case it just uses that date. Dim tDate, mDate As Date tDate = Format(Now(),"m/d/yyyy") tDay = Day(tDate) If tDay < "Monday" Then mDate = tDate - tDay The above code it what I toyed with but it has failed at every itteration I made of it. Thanks In Advance! |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
That's a Beautiful solution!!! Thanks Greatly!!
"Mike H" wrote: Rob, Try this tDate = Date - WeekDay(Date, 2) + 1 For future work you simply change the last 1 to a 2 for Tuesday etc. Mike "Rob" wrote: I was wondering how I can get VBA in Excel'03 to recognize that if today is Tuesday the 17th, or Firday the 20th, then the previous Monday must have been the 16th. Or is it is Friday April the 3rd then the previous Monday was March 30th? Escentially I am just looking for a way to have the VB identify what Day today is as well as the date and then calculate what the previous Monday was... Unless the current day happens to actually be Monday, in which case it just uses that date. Dim tDate, mDate As Date tDate = Format(Now(),"m/d/yyyy") tDay = Day(tDate) If tDay < "Monday" Then mDate = tDate - tDay The above code it what I toyed with but it has failed at every itteration I made of it. Thanks In Advance! |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Dear Rob, please try this
If this helps click Yes --------------- Jacob Skaria Dim varDate,monDate varDate = Date monDate = Format(varDate - (IIf(Weekday(varDate) = vbMonday, Weekday(varDate) - vbMonday, 7 - (vbMonday - Weekday(varDate))))) |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
A specific date used for calculation of a new date | Excel Discussion (Misc queries) | |||
Date Calculation (from entered date / 1yr later in next field) | Excel Worksheet Functions | |||
End Date Calculation (adding a start date duration) | Excel Discussion (Misc queries) | |||
Tricky Date calculation: How to calculate a future date | Excel Discussion (Misc queries) | |||
Coding to show first _weekday_ prior to a date, when date calculation happens to fall on weekend? | Excel Programming |