datetime - Getting Date of Monday of each week -
i want date of monday each week. using date open folder created every monday , named based on date. tried using weekday() function. not sure how proceed. help! have tried, works. juts wanted know if there more efficient way it?
sub test() dim myday integer dim mydate date mydate = date myday = weekday(date, vbmonday) if myday = 1 mydate = date elseif myday = 2 mydate = dateadd("d", -1, date) elseif myday = 3 mydate = dateadd("d", -2, date) elseif myday = 4 mydate = dateadd("d", -3, date) elseif myday = 5 mydate = dateadd("d", -4, date) end if end sub
if dt date, , if want return same date if dt monday, then, using vba:
function firstmonday(dt date) date firstmonday = dt - weekday(dt, vbmonday) + 1 end function
or, on worksheet, date in a1:
=a1+1-weekday(a1-1)
Comments
Post a Comment