1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Windows Excel rage - counting words, simple right?

Discussion in 'Tech Support' started by Mister_Tad, 13 Mar 2020.

  1. Mister_Tad

    Mister_Tad Will work for nuts Super Moderator

    Joined:
    27 Dec 2002
    Posts:
    14,085
    Likes Received:
    2,451
    So try as I might, I can't see a way that's not pointlessly convoluted to check how many times a given word appears in a given column.

    For example, let's say column A is text as follows...

    1. | Bacon is my favourite
    2. | I really like bacon
    3. | Prefers eggs
    4. | who loves bacon

    So I want a simple way to return 3, case insensitive instances of the word bacon within a string. Problem being it's a string within a string, so it seems to me like to do this I have to use SEARCH to look for the term bacon, and then sum/count however many rows return a value, which seems pointlessly convoluted.

    I can't edit the source data, and I need to do this across thousands of rows, for dozens of words.

    So am I entirely missing something, or is excel indeed pointlessly convoluted.
     
  2. RedFlames

    RedFlames ...is not a Belgian football team

    Joined:
    23 Apr 2009
    Posts:
    15,426
    Likes Received:
    3,013
    IIRC - You don't count the words, you count the spaces, something like this -

    Code:
    =LEN(A1)-LEN(SUBSTITUTE(A1," ",""))+1
     
  3. TaRkA DaHl

    TaRkA DaHl Modder

    Joined:
    15 Mar 2011
    Posts:
    1,702
    Likes Received:
    175
    If the strings are in column A, in column B type the word you want, in column C put the following:

    =(LEN(A1)-LEN(SUBSTITUTE(A1,B1,"")))/LEN(B1)

    If will display a count of the word, then do an autosum.
     
  4. Mister_Tad

    Mister_Tad Will work for nuts Super Moderator

    Joined:
    27 Dec 2002
    Posts:
    14,085
    Likes Received:
    2,451
    @RedFlames I'm not sure I follow, unless you mean you use SEARCH and then get the location at which the word "bacon" is, and then count how many of the rows that return a value, which to me is pointlessly convoluted.

    @TaRkA DaHl - that would be serviceable if I had one word, but...

    Basically the scenario is, let's say I asked thousands of people what they think of breakfast, and have a free text response.
    So I want to look in those respones how many mentioned the words "bacon", "eggs", "coffee" and so on to get an idea of what type of food they like.
    I also want to look for "love", "hate", "like", "okay" to get a general view of what their overall sentiment towards the meal in general is.

    As an added bonus, let's say I have emails as well, so I want to also get some info around where they are based on .uk, .jp, .cn and so on.

    So when all is said and done be able to say things like, people in japan aren't fussed on breakfast in general, but those that like it most usually like eggs, and so on.

    Clearly this has nothing to do with breakfast, but the example holds.

    EDIT: Okay I kinda geddit, but then how do I scale that without loads of legwork?

    So say in sheet 2, I want to stack up keywords in column A, and then an automagical convoluted formula that works out how many times each of those words are in column X of sheet 1 in column B - is this just unrealistic expectations?
     
    Last edited: 13 Mar 2020
  5. RedFlames

    RedFlames ...is not a Belgian football team

    Joined:
    23 Apr 2009
    Posts:
    15,426
    Likes Received:
    3,013
    something like? -

    =COUNTIF(A1:A4,"*bacon*")

    Caveat - running on no sleep, may have mis-read the question
     
    Mister_Tad likes this.
  6. Mister_Tad

    Mister_Tad Will work for nuts Super Moderator

    Joined:
    27 Dec 2002
    Posts:
    14,085
    Likes Received:
    2,451
    Urgh. Yeah so that's basically exactly it. I looked at COUNTIF but then didn't realise I can just slap *s around bacon.

    I'd like to stack certain results too, but beggars can't be choosers at this point.
     
  7. Fingers66

    Fingers66 Kiwi in London

    Joined:
    30 Apr 2010
    Posts:
    8,874
    Likes Received:
    1,054
  8. bawjaws

    bawjaws Multimodder

    Joined:
    5 Dec 2010
    Posts:
    4,284
    Likes Received:
    891
    You can also use COUNTIFS to include multiple criteria (but it's strictly AND not OR) and each criterion can be in a different range if required. Not sure if that helps you but it's an option.

    If you want to use OR logic with multiple criteria then it's a bit trickier, especially if you have lots of criteria. You can do clever stuff with array formulae - see this link: https://www.ablebits.com/office-addins-blog/2014/07/10/excel-countifs-multiple-criteria/
     
    Mister_Tad likes this.
  9. Mister_Tad

    Mister_Tad Will work for nuts Super Moderator

    Joined:
    27 Dec 2002
    Posts:
    14,085
    Likes Received:
    2,451
    This is perfect. I slapped something together earlier that let me come to a few initial interesting conclusions, but could do with tidying things up a bit and this will do nicely.

    Bit-tech to the rescue!
     
  10. bawjaws

    bawjaws Multimodder

    Joined:
    5 Dec 2010
    Posts:
    4,284
    Likes Received:
    891
    To be honest, Excel is pretty crap a lot of the time, and it's particularly crap at letterz, but the good thing about it is that there are so many online resources that you can almost always find a way to do what you want, even if it's not necessarily particularly straightforward!

    And when cell formulae fail, there's always VBA :grin:
     
  11. Dr. Coin

    Dr. Coin Multimodder

    Joined:
    13 Sep 2013
    Posts:
    1,102
    Likes Received:
    296
    To be fair excel is a pretty solid spreadsheet, i.e. accounting tool. Most of excel's crap behavior extends from people using it as a database and using functions to build queries.
     
  12. bawjaws

    bawjaws Multimodder

    Joined:
    5 Dec 2010
    Posts:
    4,284
    Likes Received:
    891
    Aye, that's pretty much what I was getting at :) If I had a pound for every time I've had to tell someone "EXCEL IS NOT A DATABASE" then I'd be extremely rich indeed!
     

Share This Page