Date/Day VBA Calculation

R

Rob

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!
 
M

Mike H

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
 
M

Mike H

And including your formatting

tDate = Format(Date - WeekDay(Date, 2) + 1, "mm/dd/yyyy")

Mike
 
J

Jacob Skaria

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)))))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top