+ Reply to Thread
Results 1 to 18 of 18

count number of records per month

Hybrid View

  1. #1
    Registered User
    Join Date
    11-08-2006
    Posts
    15

    count number of records per month

    I have a spreadsheet that users are filling in using a userform. Due to the fact that some data may be pre/post dated for entry I am trying to find a way that I can count the number of records per month.

    What I have been trying to use (with no luck) is COUNTIF:

    =COUNTIF(E2:E50,TEXT(MONTH(E2:E50), "00"), "05")
    What this should do is count the number of times an entry has a month of "05" by testing the month of each entry in a range in column E from 2 to 50.

    I would also like this to compute using any filled in rows, not just a static number. It is not a problem to move this to vba if that is easier, I just need some help pointing me in the right direction.

    Thanks,

    Dan

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    Try

    =SUMPRODUCT(--(MONTH(E2:E50)=5))

    Use a dynamic range instead of E2:E50. Link will show you how

    http://www.contextures.com/xlNames01.html#Dynamic

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Try:

    =SUMPRODUCT(--(TEXT(MONTH(E2:E50),"00")="05"))

    If your date is entered as a true date and not a text string, then this too should work

    =SUMPRODUCT(--(MONTH(E2:E50)=5))
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  4. #4
    Registered User
    Join Date
    11-08-2006
    Posts
    15
    Thanks to both of you!

    Now if you do not mind answering a follow up, what does the '--' do?

    And if I wanted to know how many times the same person reported something for the month would it be like this?

    =SUMPRODUCT(--(MONTH(E2:E50)=5)*(A2:A50="Joe Doe"))
    Thanks,

    Dan
    Last edited by HurricaneDan; 05-08-2007 at 02:09 PM.

  5. #5
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Quote Originally Posted by HurricaneDan
    Thanks to both of you!

    Now if you do not mind answering a follow up, what does the '--' do?

    And if I wanted to know how many times the same person reported something for the month would it be like this?

    =SUMPRODUCT(--(MONTH(E2:E50)=5)*(A2:A50="Joe Doe"))
    Thanks,

    Dan
    Close.... =SUMPRODUCT(--(MONTH(E2:E50)=5),--(A2:A50="Joe Doe"))


    The "--" is a double unary and acts as a coercer to change Trues and Falses to 1's and 0's, respectively, so that the Sumproduct can perform the necessary arithmetic to get the result.

  6. #6
    Registered User
    Join Date
    11-08-2006
    Posts
    15
    NBVC,

    Thanks again for the help. I have run into one issue where it can be an either or answer for a question. What do you do if a field is blank midway through a column? It causes the #VALUE! error.

    Thanks again,

    Dan

  7. #7
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Quote Originally Posted by HurricaneDan
    NBVC,

    Thanks again for the help. I have run into one issue where it can be an either or answer for a question. What do you do if a field is blank midway through a column? It causes the #VALUE! error.

    Thanks again,

    Dan
    Can you be more specific? Which column? And why blank?

  8. #8
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    Here's another one - a bit more stepwise but gives the same answer and is adaptable to periods other than complete calendar months.
    Attached Files Attached Files

+ 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.6.0 RC 1