+ Reply to Thread
Results 1 to 15 of 15

Using a countif function for text string data.

  1. #1
    Registered User
    Join Date
    02-08-2008
    Location
    Co. Down, Ireland.
    Posts
    53

    Using a countif function for text string data.

    Hi everyone.

    I'm currently working on a spreadsheet (see attached) which will have both numeric and text string data. This will be sorted by calender month and linked to another spreadsheet.

    Could someone please list 2 functions for me.

    The 1st would allow act like a filter allowing only data to be counted for a selected month from a drop down list.

    The 2nd allows a counting of pre-set (drop down list) text strings to be counted.

    Sorry seems a bit complicated and really I should have either a created a pivot report or used access but I'd like to continue with Excel for this exercise.

    Thanks in advance.
    Attached Files Attached Files

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    For the 1st try: =COUNT(IF(MONTH($B$20:$B$507+0)=MONTH(D$6),1,"")) confirmed with CTRL+SHIFT+ENTER..

    I don't see where the 2nd applies...?
    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.

  3. #3
    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
    Or without an array

    =SUMPRODUCT(--(TEXT($B$20:$B$507,"mm")=TEXT($D$5,"mm")))
    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 !!!

  4. #4
    Registered User
    Join Date
    02-08-2008
    Location
    Co. Down, Ireland.
    Posts
    53
    I'm so sorry it sounds very confusing.

    If you look at the spreadsheet, row D7 to D16 are the questions I need answered from the data entered below it.

    I managed to get the countif function done to count how many clients were on for a month selceted from the drop down list in cell D5.

    What I now need to do is add a similar function where I can change the logical test so that it counts text strings (which are selected from a drop down list within the spreadsheet) for cells D8, D10, D12, D15 & D16.

    The trouble I have is that there are numerous text strings click on cell L20 for example. Also to add to the complications one of the drop down entires may need the data inputer to add extra text into cell M20......

    AAAAAAAAGGGGGGGHHHHHHHH Its not going to work, I just know it......

  5. #5
    Registered User
    Join Date
    02-08-2008
    Location
    Co. Down, Ireland.
    Posts
    53
    {=COUNT(IF(B$20:B507=D$6,1,""))}

    The above is my basic formula for the array yet where can I add another function within the above to count text strings etc....

  6. #6
    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
    What's your expected results ??

    A total of Unquie items or list all 30 answer in one cell with a count ??

    e.g for D9 would you have something like

    ="Males Tot "&COUNTIF(K:K,"male")&" / "&"Female Tot "&COUNTIF(K:K,"Female")
    VBA Noob

  7. #7
    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
    Looking at your data I would think about using Advance filter as will give you flexiblity. See link for more. Make sure to look at 2nd link for filtering criteria

    http://www.contextures.com/xladvfilter01.html

    VBA Noob
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    02-08-2008
    Location
    Co. Down, Ireland.
    Posts
    53
    I think your right VBA Noob... I'm asking too much...

  9. #9
    Registered User
    Join Date
    02-08-2008
    Location
    Co. Down, Ireland.
    Posts
    53
    Quote Originally Posted by VBA Noob
    What's your expected results ??

    A total of Unquie items or list all 30 answer in one cell with a count ??

    e.g for D9 would you have something like



    VBA Noob
    What I'd like to set up is a function like below whereby the first part 'COUNT(IF(B$20:B507=D$6,1,"")' will set the filter so that the only months selected from the drop down list will be counted. The second part of the function would then be used to count the different areas I need to get (cells C8-C16).

    For example to count all males within the selected month would work out as;

    {=COUNT(IF(B$20:B507=D$6,1,"")*AND(SUM($K$20:$K$508="Male")))} - This does'nt work but used as an example.

    (Thanks for your help by the way)....

  10. #10
    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
    I'm asking too much
    I never said that. I suggested a possible alternative.


    What's your expected results ??

    A total of Unquie items or list all 30 answer in one cell with a count ??

    e.g for D9 would you have something like


    Quote:
    ="Males Tot "&COUNTIF(K:K,"male")&" / "&"Female Tot "&COUNTIF(K:K,"Female")
    Also you never answered this question

    VBA Noob

  11. #11
    Registered User
    Join Date
    02-08-2008
    Location
    Co. Down, Ireland.
    Posts
    53
    sorry......

    Well I'm linking the answers into another sheet that will state;

    Number of males =
    Number of females =

    So I suppose a single count? I'll add another row for counting females?

    Tell me Noob, how would this apply to the more complicated answers, such as the drop down list in cell L20???
    Last edited by Stevie-B; 03-11-2008 at 07:29 AM.

  12. #12
    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
    What's your expected results ??

    A total of Unquie items or list all 30 answer in one cell with a count ??
    Still didn't answer it.

    Maybe post a sample with expected results in those cells

    VBA Noob

  13. #13
    Registered User
    Join Date
    02-08-2008
    Location
    Co. Down, Ireland.
    Posts
    53
    A total of Unquie items. This could then be linked into another spreadsheet.
    Attached Files Attached Files

  14. #14
    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
    Try this in D10 for starters



    =SUMPRODUCT(--(TEXT(A22:A200,"MMYY")=TEXT(D5,"MMYY"))*(K22:K200="Male")*(G22:G200="Armagh / Dungannon"))
    If you change D3 to a drop down then use
    =SUMPRODUCT(--(TEXT(A22:A200,"MMYY")=TEXT(D5,"MMYY"))*(K22:K200="Male")*(G22:G200=D3))
    For unique items try e.g D12 would be
    =SUMPRODUCT((J22:J200<>"")/COUNTIF(J22:J200,J22:J200&""))
    Change ranges as required

    VBA Noob
    Last edited by VBA Noob; 03-11-2008 at 11:14 AM.

  15. #15
    Registered User
    Join Date
    02-08-2008
    Location
    Co. Down, Ireland.
    Posts
    53
    VBA Noob........ you are fantastic. I'm going to try these now and get back to you with the results!

    Thanks very much.

+ 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