View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default count wednesdays within a month

I find something like this formula easier to understand.

=SUMPRODUCT(--(TEXT(ROW(INDIRECT(DATE(2010,1,1)
&":"&DATE(2010,12,31))),"mmmddd")="FebWed"))

I'm sure that it's much slower than Biff's, but it's pretty straight forward.

The biggest thing is the =indirect() function. That just makes it so that excel
sees this string:
date(2010,1,1)&":"date(2010,12,31)
as a range of rows.

Date(2010,1,1) is just a number that's nicely formatted to excel. If you format
it as general, you'll see 40179 (with a base date of 1904).

=sumproduct() likes to work with numbers, so the -- stuff changes a bunch of
true/false's to 1's and 0's.

And if you put the start date in A1 and the end date in A2, the formula changes
to:

=SUMPRODUCT(--(TEXT(ROW(INDIRECT(a1&":"&a2)),"mmmddd")="FebWed") )

And if you wanted to count the number of days in that time interval, you'd
change the format and the string to look for:

=SUMPRODUCT(--(TEXT(ROW(INDIRECT(A1&":"&A2)),"ddd")="Wed"))



sato wrote:

I want to count how many let's say wednesdays are within a calendar month and
for each month of the year
--
sato panago


--

Dave Peterson