+ Reply to Thread
Results 1 to 10 of 10

UDF to count letters in a range

  1. #1
    Registered User
    Join Date
    09-22-2014
    Location
    Silicon Valley, California
    MS-Off Ver
    2007
    Posts
    40

    UDF to count letters in a range

    I need to get a count of the number of occurrences of each of the letters (A-Z) in a range.

    The input range contains names like this:

    ALICE
    FRED
    SALLY
    MARK
    HENRY
    JUDY

    The output would be another range like this

    A 3
    B 0
    C 1
    D 2
    E 3
    … …
    Z 0

    I'd like to be able to call the UDF like this: =LetterTally(B2:B75,E2).

    B2:B75 is the input range.
    E2 is the upper left hand corner of the output range.

    The names should all be upper case, but the tally should be case insensitive (A=a).

    Can someone get me started? I am having trouble setting up the output array and using the letters to index into it?

    I'm also having trouble with how to write the result to the sheet. If this is not possible, it's OK to write to a text file or even just display it on the screen.

    Thanks

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: UDF to count letters in a range

    Unfortunately its late and my minds not working fully but this will calculate what you're after, trouble is the outputting isnt working so ive output to message box for test purposes:

    Please Login or Register  to view this content.
    If someone has helped you then please add to their Reputation

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

    Re: UDF to count letters in a range

    a formula to do it
    =SUMPRODUCT(--(MID($A$1:$A$100,COLUMN(1:255),1)=E1)) where e1:a26 = a through z
    "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

  4. #4
    Registered User
    Join Date
    09-22-2014
    Location
    Silicon Valley, California
    MS-Off Ver
    2007
    Posts
    40

    Re: UDF to count letters in a range

    Quote Originally Posted by pjwhitfield View Post
    Unfortunately its late and my minds not working fully but this will calculate what you're after, trouble is the outputting isn't working so I've output to message box for test purposes:
    This does seem to work once I got all the variables properly declared. I run with Option Explicit.

  5. #5
    Registered User
    Join Date
    09-22-2014
    Location
    Silicon Valley, California
    MS-Off Ver
    2007
    Posts
    40

    Re: UDF to count letters in a range

    Quote Originally Posted by martindwilson View Post
    a formula to do it
    =SUMPRODUCT(--(MID($A$1:$A$100,COLUMN(1:255),1)=E1)) where E1:E26 = a through z
    Wow. That's amazing! (I had to fix the typo "e1:a26".)

    What does the "COLUMN(1:255)" do?

    Can this be modified to work on a 2-dimensional range?

    Please Login or Register  to view this content.
    I tried it, but got an error.

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

    Re: UDF to count letters in a range

    so do i! but row(1:255) in mid() gives
    say mid(a1,row(1:255),1) each letter in turn essentially {mid(a1,1,1)&";"mid(a1,2,1)&";"mid(a1,3,1).....&";"mid(a1,255,1)}
    but i think i made an error this is quicker
    =SUMPRODUCT(--(MID($A$1:A20,COLUMN(A:IU),1)=E1))
    Last edited by martindwilson; 12-22-2014 at 08:13 PM.

  7. #7
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: UDF to count letters in a range

    Here is another version to count letters

    =SUMPRODUCT(LEN($B$2:$B$75)-LEN(SUBSTITUTE($B$2:$B$75,E2,"")))
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  8. #8
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: UDF to count letters in a range

    using modified code from PJ
    Don't know how to output range with UDF...let alone a different range

    caters for spaces and is not case sensitive


    highlight area you want done
    modify output range in code to whatever you want
    Attached Files Attached Files
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,595

    Re: UDF to count letters in a range

    UDF

    Use in cell like
    =IFERROR(LetterTally($B$2:$B$7,ROW(A1),COLUMN(A1)),"")
    Copy to the right adjacent cell then copy both cells down
    Please Login or Register  to view this content.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    09-22-2014
    Location
    Silicon Valley, California
    MS-Off Ver
    2007
    Posts
    40

    Re: UDF to count letters in a range

    Thanks, everyone, for the helpful responses. I have something that works. Much appreciation.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Count specific phrase (letters and numbers) in continuous range
    By macneill5 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-03-2012, 04:56 AM
  2. Count Letters in Range
    By rajuabju in forum Excel General
    Replies: 10
    Last Post: 07-20-2009, 08:48 PM
  3. count letters
    By kristygrippo in forum Excel General
    Replies: 3
    Last Post: 04-07-2009, 03:02 PM
  4. How do i count numbers and letters to find a total count of all
    By Linda in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-10-2005, 12:55 PM
  5. Count letters
    By JIM.H. in forum Excel General
    Replies: 4
    Last Post: 07-04-2005, 02:05 AM

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