ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Dating Problem (https://www.excelbanter.com/excel-programming/332379-dating-problem.html)

Gary's Student

Dating Problem
 
I need a UDF that, given a date, returns the date of the Monday of that week.
For example, if the input was a value between 6/20/2005 and 6/26/2005, the
function would return 6/20/2005. If the input was 6/27/2005 the UDF should
return 6/27/2005.

All I can think of is a massive VLOOKUP table. There has got to be a
cleaner way.

Thank you in advance

--
Gary's Student

Harald Staff

Dating Problem
 
Function WeeksMonday(Dt As Date) As Date
WeeksMonday = Dt - Weekday(Dt, vbMonday) + 1
End Function

HTH. Best wishes Harald

"Gary's Student" skrev i melding
...
I need a UDF that, given a date, returns the date of the Monday of that

week.
For example, if the input was a value between 6/20/2005 and 6/26/2005,

the
function would return 6/20/2005. If the input was 6/27/2005 the UDF

should
return 6/27/2005.

All I can think of is a massive VLOOKUP table. There has got to be a
cleaner way.

Thank you in advance

--
Gary's Student




Mangesh Yadav[_4_]

Dating Problem
 
A worksheet function:

=A1-(WEEKDAY(A1)-2)-IF((WEEKDAY(A1)-2)<0,7,0)

Mangesh



"Gary's Student" wrote in message
...
I need a UDF that, given a date, returns the date of the Monday of that

week.
For example, if the input was a value between 6/20/2005 and 6/26/2005,

the
function would return 6/20/2005. If the input was 6/27/2005 the UDF

should
return 6/27/2005.

All I can think of is a massive VLOOKUP table. There has got to be a
cleaner way.

Thank you in advance

--
Gary's Student




Gary's Student

Dating Problem
 
Thank you both
--
Gary's Student


"Mangesh Yadav" wrote:

A worksheet function:

=A1-(WEEKDAY(A1)-2)-IF((WEEKDAY(A1)-2)<0,7,0)

Mangesh



"Gary's Student" wrote in message
...
I need a UDF that, given a date, returns the date of the Monday of that

week.
For example, if the input was a value between 6/20/2005 and 6/26/2005,

the
function would return 6/20/2005. If the input was 6/27/2005 the UDF

should
return 6/27/2005.

All I can think of is a massive VLOOKUP table. There has got to be a
cleaner way.

Thank you in advance

--
Gary's Student





Ron Rosenfeld

Dating Problem
 
On Tue, 21 Jun 2005 03:29:03 -0700, "Gary's Student"
wrote:

I need a UDF that, given a date, returns the date of the Monday of that week.
For example, if the input was a value between 6/20/2005 and 6/26/2005, the
function would return 6/20/2005. If the input was 6/27/2005 the UDF should
return 6/27/2005.

All I can think of is a massive VLOOKUP table. There has got to be a
cleaner way.

Thank you in advance


What is the first day of your week?

If the first day of your week is Sunday, then:

=A1+2-WEEKDAY(A1)

If the first day of your week is Monday, then:

=A1+1-WEEKDAY(A1,2)

In VB:

Function FirstMon(dt As Date) As Date
FirstMon = dt + 2 - Weekday(dt, vbSunday)
End Function

or
Function FirstMon(dt As Date) As Date
FirstMon = dt + 1 - Weekday(dt, vbMonday)
End Function


--ron


All times are GMT +1. The time now is 05:05 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com