Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default UDF: How many Monday's in a date range?

Hi,

Newbie help needed please

I need to write 5 UDF's in Excel.

They are all similar, so let's explain the first one.

I'll pass in 2 parameters: "startdate" and "enddate".

I want to calculate the number of Mondays that exist in the date range
between startdate and enddate, and pass it back.

The other 4 UDF's are for Tues, Wed, Thurs & Fri.

Any thoughts please?

Kind Regards,

NR
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 806
Default UDF: How many Monday's in a date range?

Hello,

Put this worksheet function (the first listed one) into a macro then:
http://www.sulprobil.com/html/date_formulas.html

Regards,
Bernd
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default UDF: How many Monday's in a date range?

For Monday:

Function mondaymonday(r1 As Range, r2 As Range) As Integer
For i = r1.Value To r2.Value
If Weekday(i) = 2 Then
mondaymonday = mondaymonday + 1
End If
Next
End Function

So if A12 contains 4/6/2008
and A13 contains 4/14/2008
then =mondaymonday(A12,A13) will return:
2
--
Gary''s Student - gsnu2007g


"N Ramsay" wrote:

Hi,

Newbie help needed please

I need to write 5 UDF's in Excel.

They are all similar, so let's explain the first one.

I'll pass in 2 parameters: "startdate" and "enddate".

I want to calculate the number of Mondays that exist in the date range
between startdate and enddate, and pass it back.

The other 4 UDF's are for Tues, Wed, Thurs & Fri.

Any thoughts please?

Kind Regards,

NR

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default How many Monday's in a date range?

See below ....

Steve

Count The Number Of Sundays Between Two Dates



Public Function HowManyWD(FromDate As Date, ToDate As Date, WD As Long)
HowManyWD = DateDiff("ww", FromDate, ToDate, WD) _
- Int(WD = WeekDay(FromDate))
End Function

Example:
HowManyWD(7/1/03,7/31/03/,1) Returns the number of Sundays in July 2003

Note: Change the 1 to the following to find other days:
2 - Monday
3 - Tuesday
4 - Wednesday
5 - Thursday
6 - Friday
7 - Saturday


"N Ramsay" wrote in message
...
Hi,

Newbie help needed please

I need to write 5 UDF's in Excel.

They are all similar, so let's explain the first one.

I'll pass in 2 parameters: "startdate" and "enddate".

I want to calculate the number of Mondays that exist in the date range
between startdate and enddate, and pass it back.

The other 4 UDF's are for Tues, Wed, Thurs & Fri.

Any thoughts please?

Kind Regards,

NR



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default UDF: How many Monday's in a date range?

On 7 Apr, 17:28, Bernd P wrote:
Hello,

Put this worksheet function (the first listed one) into a macro then:http://www.sulprobil.com/html/date_formulas.html

Regards,
Bernd


Bernd, that's perfect!

Many Thanks indeed.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default UDF: How many Monday's in a date range?

It is not very complicated. Lets see if I can explain. You subtract the two
dates. You need to make an adjustment to make the start date a Monday. but
because Weekday function return 1 for the first day you need to subtract an
additional one

Sayy yoiur start date was tomorrow tuesday and the end date was Wednesday

then you pretend these dates were Monday and Tuesday and you count your week
from this new Monday. but Monday from the Weekday function is 1 so you
subtract one from the number.


Function mondays(startdate, enddate)
Startday = Weekday(startdate, vbMonday)

mondays = Int((enddate - startdate - (Startday - 1)) / 7)

End Function


"N Ramsay" wrote:

Hi,

Newbie help needed please

I need to write 5 UDF's in Excel.

They are all similar, so let's explain the first one.

I'll pass in 2 parameters: "startdate" and "enddate".

I want to calculate the number of Mondays that exist in the date range
between startdate and enddate, and pass it back.

The other 4 UDF's are for Tues, Wed, Thurs & Fri.

Any thoughts please?

Kind Regards,

NR

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default UDF: How many Monday's in a date range?

Thanks also to Steve and Gary for quick responses.

Not sure which one to go for, but many thanks to all.

Kind Regards

NR
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
How do I convert a date to Monday's date within its week? Sorsy Excel Worksheet Functions 7 October 9th 08 06:48 PM
Need formula to return next Monday's date Frustrated in Portland Excel Worksheet Functions 4 July 15th 08 06:12 PM
Given today's date, I want this week's Monday's date BlueWolvering Excel Worksheet Functions 3 February 12th 08 06:16 PM
Display Monday's date only on x-axis Bruce Charts and Charting in Excel 1 August 18th 07 02:52 PM
copy date based on date -refer to date range mindpeace[_4_] Excel Programming 1 June 3rd 06 01:30 PM


All times are GMT +1. The time now is 12:35 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"