+ Reply to Thread
Results 1 to 5 of 5

Thread: Count dayname equal to

  1. #1
    Valued Forum Contributor
    Join Date
    11-02-2007
    Location
    Bryne, Norway
    MS-Off Ver
    Microsoft Office Excel 2003
    Posts
    213

    Count dayname equal to

    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.

  2. #2
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: Count dayname equal to

    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

  3. #3
    Forum Guru sweep's Avatar
    Join Date
    04-03-2007
    Location
    Location: Location:
    MS-Off Ver
    3.0
    Posts
    2,472

    Re: Count dayname equal to

    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.

  4. #4
    Valued Forum Contributor
    Join Date
    11-02-2007
    Location
    Bryne, Norway
    MS-Off Ver
    Microsoft Office Excel 2003
    Posts
    213

    Re: Count dayname equal to

    All of it works. Thank you :-)

  5. #5
    Valued Forum Contributor
    Join Date
    11-02-2007
    Location
    Bryne, Norway
    MS-Off Ver
    Microsoft Office Excel 2003
    Posts
    213

    Count daynames in a defined week

    -----------------------------------------------
    Last edited by mkvassh; 03-18-2010 at 09:47 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0