+ Reply to Thread
Results 1 to 9 of 9

How to count characters in a number of cells?

  1. #1
    Registered User
    Join Date
    01-11-2007
    Posts
    4

    How to count characters in a number of cells?

    Hello,
    Hope someone can help me with this.
    I want to count how many f.ex. a's there is in a number of cells. This is what I have:

    A1: aaaf
    A2: faas
    A3:
    A4: ffhhh

    I've found out how to count the number of a's in one cell - like this:

    =LEN(A1)-LEN(SUBSTITUTE(A1;"a";""))
    The result is 3

    But how can I make one calculation that will do the same calculation for a lot of cells and add all the results.... The result from doing it on the 4 cells above should be 5.

    I know I could 'just' repeat the calculation manually, but since I must add the results from 52 cells (one for every week in a year) it would be a huge calculation and I'm sure it can be done much easier - I just don't know how...

    Kind regards,
    Staalander

  2. #2
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by Staalander
    Hello,
    Hope someone can help me with this.
    I want to count how many f.ex. a's there is in a number of cells. This is what I have:

    A1: aaaf
    A2: faas
    A3:
    A4: ffhhh

    I've found out how to count the number of a's in one cell - like this:

    =LEN(A1)-LEN(SUBSTITUTE(A1;"a";""))
    The result is 3

    But how can I make one calculation that will do the same calculation for a lot of cells and add all the results.... The result from doing it on the 4 cells above should be 5.

    I know I could 'just' repeat the calculation manually, but since I must add the results from 52 cells (one for every week in a year) it would be a huge calculation and I'm sure it can be done much easier - I just don't know how...

    Kind regards,
    Staalander
    Hi,

    why not formula fill down the next column and then Subtotal on that column ?

    Formula fill is shown at http://www.mvps.org/dmcritchie/excel/fillhand.htm

    hth
    ---
    Si fractum non sit, noli id reficere.

  3. #3
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi,
    Please Login or Register  to view this content.
    HTH
    Carim


    Top Excel Links

  4. #4
    Registered User
    Join Date
    01-11-2007
    Posts
    4
    Bryan - I would prefer to do it all in one calculation because I have many columns that I need to count and don't want to double the columns with a subtotal column. But thanks.

    Carim - that looks like exactly what I want to accomplish - only problem is I'm quite an amateur in Excel so I have no idea where to code it - how do I put code in a cell ?? How about a link where I can learn 'how to'... Thanks.

    Staalander

  5. #5
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi,

    1. Alt F11
    2. Insert Module
    3. Copy Macro

    That's it ...

  6. #6
    Registered User
    Join Date
    01-11-2007
    Posts
    4
    OK, now I've got a macro (in a module) - and I get the correct result if I mark a number of cells and run the macro on them.

    But is there a way to put the result in a cell - just as if it was an ordinary formula/calculation ?? Something like "EXECUTE 'countit' on (A1:A4)" ... ??

    Staalander

  7. #7
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi,

    Just replace
    For Each cel In Selection
    by
    For Each cel In Range("A1:A4")

  8. #8
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Quote Originally Posted by Staalander
    =LEN(A1)-LEN(SUBSTITUTE(A1;"a";""))
    The result is 3

    But how can I make one calculation that will do the same calculation for a lot of cells
    With a formula.....

    =SUMPRODUCT(LEN(A1:A52)-LEN(SUBSTITUTE(A1:A52;"a";"")))

  9. #9
    Registered User
    Join Date
    01-11-2007
    Posts
    4

    Talking Yes!!

    Thank you!! - that is exactly what I wanted - imagine that it was so simple...

    Kind regards
    Helle Staalander

+ 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