+ Reply to Thread
Results 1 to 15 of 15

count number of time a text string appears

  1. #1
    Registered User
    Join Date
    08-22-2003
    Posts
    11

    count number of time a text string appears

    Did a search on the forum but didn't find a similar thread. I have a very large spreadsheet and want to count the number of times a particular text string shows up in a column. I can't use autofilter due to the 1000 limit.

    Here's an example, Column C contains:
    Dan Parker
    John Doe
    Dan Smith
    Jill Smith

    So if I search on *Dan*, the function should return a count of 2.

    I've used COUNTIF before to return values when the whole cell = a certain value but in my case the cell may have 200 characters and I want to count based on a fuzzy search. I would like to do this in a function and not a macro. Any help would be appreciated.

  2. #2
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264
    Quote Originally Posted by wolfpack95
    Did a search on the forum but didn't find a similar thread. I have a very large spreadsheet and want to count the number of times a particular text string shows up in a column. I can't use autofilter due to the 1000 limit.

    Here's an example, Column C contains:
    Dan Parker
    John Doe
    Dan Smith
    Jill Smith

    So if I search on *Dan*, the function should return a count of 2.

    I've used COUNTIF before to return values when the whole cell = a certain value but in my case the cell may have 200 characters and I want to count based on a fuzzy search. I would like to do this in a function and not a macro. Any help would be appreciated.

    Hi

    You can use COUNTIF:

    =COUNTIF(A:A,"*Dan*")

    This isn't a case-sensitive search, so this will pick up Dan, Daniel, Shodan etc.

    There isn't a 1000 limit on Autofilter - what there is is a 1000 limit on the unique values that can be displayed in the Autofilter dropdown, but the filtered results on the sheet will contain all the matching values.

    Hope this helps!

    Richard

  3. #3
    Registered User
    Join Date
    08-22-2003
    Posts
    11
    Quote Originally Posted by RichardSchollar
    Hi

    You can use COUNTIF:

    =COUNTIF(A:A,"*Dan*")

    This isn't a case-sensitive search, so this will pick up Dan, Daniel, Shodan etc.

    There isn't a 1000 limit on Autofilter - what there is is a 1000 limit on the unique values that can be displayed in the Autofilter dropdown, but the filtered results on the sheet will contain all the matching values.

    Hope this helps!

    Richard
    Well, that was easy . I tried this before posting but had an error in my formula. It's working now. Thanks.

  4. #4
    Registered User
    Join Date
    12-20-2009
    Location
    Melbourne
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: count number of time a text string appears

    Hey guys, I saw this, and it helps me, but I have a slightly different problem. I am looking for the total number of times a name appears within a field, not just how many fields it appears in.

    For example, if a field had

    Dan Dan
    Dan Parker
    John Doe
    Dan Smith
    Jill Smith

    then that code would produce a 3. I want the code that would produce the overall number of times that the string was found. Which is 4. Can somebody please help me with that?

  5. #5
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: count number of time a text string appears

    You can do a Find and Replace (Ctrl+H)
    Find: Dan
    Replave with: Dan
    (effectively nothing changes)
    The MsgBox will display the # of replacements.
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  6. #6
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,614

    Re: count number of time a text string appears

    Except if there's some word that contrains Dan (Dante, Prodan)

  7. #7
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: count number of time a text string appears

    ... or

    =SUM(--(MID(A1:A5,COLUMN(A1:I5),3)="Dan"))

    Make it an array function by Shift+Ctrl+Enter

  8. #8
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: count number of time a text string appears

    Or ruling Dante out

    =SUM(--(MID(" "&A1:A6&" ",COLUMN(A1:K6),5)=" Dan "))

  9. #9
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: count number of time a text string appears

    =(LEN(A1)-LEN(SUBSTITUTE(A1,"Dan","")))/LEN("Dan")
    but as zbor says this will also count Dante, Prodan
    and {=SUM(--(MID(" "&A1:A6&" ",COLUMN(A1:K6),5)=" Dan ")) }
    only counts 9 dans in this when the answer is 13
    Dan Dan Danger
    Dan Parker Dan
    Dan Dan Danger Dan
    Dan Smith
    Jill Dan Smith Dan
    Dan Dan Danger Dan
    but if you download the more func add in
    http://download.cnet.com/Morefunc/30...-10423159.html
    you can use
    =REGEX.COUNT(A2,"\bDan\b")
    Last edited by martindwilson; 12-20-2009 at 09:14 AM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  10. #10
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: count number of time a text string appears

    .... Martin ....

    Enlarge COLUMN(A1:K6) ot COLUMN(A1:AA6) or larger ?

    No regular expressions required.

  11. #11
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: count number of time a text string appears

    yep thats fine but regex are so much more fun!

  12. #12
    Forum Contributor
    Join Date
    06-09-2009
    Location
    Wales
    MS-Off Ver
    Excel 2003
    Posts
    155

    Re: count number of time a text string appears

    I'm not sure I'm allowed to do this on somebodies thread, but I read with interest and I have an issue probably a whole lot more simple yet similar (in my mind anyway!)

    I have a table of numbers and am trying to ascertain pairs within each horizontal line i.e. how many times if a 1 appears does a 2 also appear. It's a repetitive task as I have to do the same for 1 & 3, then 1 & 4 up to 20 and then start the process again on 2 ie. 2&1 2&3 2&4 etc... takes me bloody ages!!

    I figured about doing =if(1,A2:D5,(countif(A2:D5,2))"") I attached the example but it returns errors that I can't figure out. You guys inspired me to sign up for a VB course to take things a step further but I'm only one month in and still on forms etc so not sure if you can help me with either the VB or a formula?

    regards

    Simon
    Attached Files Attached Files

  13. #13
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: count number of time a text string appears

    Indeed not allowed!!
    Open a new thread and refer to this thread.
    Copy address and paste like this
    HTML Code: 

  14. #14
    Forum Contributor
    Join Date
    06-09-2009
    Location
    Wales
    MS-Off Ver
    Excel 2003
    Posts
    155

    Re: count number of time a text string appears

    apologies have posted hopefully correctly and referred to the html. hope that's ok.

  15. #15
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: count number of time a text string appears

    Joeeey, this thread is more than two years old. From now on please start your own thread and feel welcome to link to an old thread you want to refer to.

    Opsman, you'd also better have a look at the forum rules again!

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.

+ 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