Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default 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




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Spreadsheet Dating Issue VegasBurger Excel Discussion (Misc queries) 11 August 1st 08 11:45 PM
Dating a file. Matt S Excel Discussion (Misc queries) 4 July 22nd 08 06:57 PM
How do I change from american dating to uk dating? Ile Esturo Excel Worksheet Functions 1 November 28th 06 04:45 PM
How to update dating? Craig New Users to Excel 1 October 28th 06 08:09 PM
dating problems! Jose Mourinho Excel Worksheet Functions 4 January 12th 05 05:03 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"