I have a range with dates and I want to count dayname equal to mon, tue, wed.....sun.
I use a user defined function like the one below, but it is difficult to get this one to work together wiht COUNTIF.
Any suggestion?
Function DayName(InputDate As Date) 'Day name based on date Dim DayNumber As Integer DayNumber = Weekday(InputDate, vbSunday) Select Case DayNumber Case 1 DayName = "Sunday" Case 2 DayName = "Monday" Case 3 DayName = "Tuesday" Case 4 DayName = "Wednesday" Case 5 DayName = "Thursday" Case 6 DayName = "Friday" Case 7 DayName = "Saturday" End Select End Function
Last edited by mkvassh; 03-18-2010 at 09:47 AM.
Not sure you really need a UDF here - it will generally perform slower than native functions...
=SUMPRODUCT(--(WEEKDAY(range)=1))
would give count of Sundays though assumes all values within range are valid dates, if not,
=SUMPRODUCT(--(TEXT(range;"dddd")="Sunday")))
amend per own local requirements
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Hi,
Would this work for you?
=SUMPRODUCT((WEEKDAY(A1:A25)=daynumber)*1)
where dayname is a number between 1 and 7 representing sunday to saturday.
Please disregard anything in the above post. It may well have been edited without my consent, as has been the case with several posts and threads recently.
All of it works. Thank you :-)
-----------------------------------------------
Last edited by mkvassh; 03-18-2010 at 09:47 AM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks