+ Reply to Thread
Results 1 to 4 of 4

count duplicate characters at the end of a dynamic string

  1. #1
    Registered User
    Join Date
    10-25-2013
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    79

    count duplicate characters at the end of a dynamic string

    hello, i have a range of cells that get filled with the letters "W", "L", "O", and "T" from a series of macros. what i am wondering if there is a simple way to analyze the string, and depending on which letter is last, count how many of that letter are in a row at the end of the string.

    examples: string "W" desired outcome "1" as there is only the one character
    string "LOOTWW" desired outcome "2" as the last two characters are the same
    string "WWWLWWWWWW" desired outcome "6" as the last six characters are the same

    i have the following code that does the trick, however i was wondering if there was a simpler way to achieve this as it is quite long and bulky.

    Please Login or Register  to view this content.
    the whole code includes the same for the other characters

    thanks to anyone who has any suggestions


    *well i was just about to post this and then i thought maybe a for loop would work and quickly started tinkering and came up with something nice and simple that seems to work, but i will post anyways in case someone could find it useful

    Please Login or Register  to view this content.
    :D

  2. #2
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: count duplicate characters at the end of a dynamic string

    Maybe:
    Please Login or Register  to view this content.
    and use for instance by:
    Please Login or Register  to view this content.
    or directly with reference to a cell with the same info, e.g. =CountW(A1)

    Hope this helps.

    Best,
    berlan
    Last edited by berlan; 06-15-2015 at 04:07 PM.

  3. #3
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: count duplicate characters at the end of a dynamic string

    I was also thinking of using Regular Expressions, which I am new to, but I took a different approach than Berlan.

    Please Login or Register  to view this content.
    Last edited by skywriter; 06-15-2015 at 06:14 PM.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  4. #4
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: count duplicate characters at the end of a dynamic string

    For your OP question, with string in cell C5 (this post is just for the record)
    Please Login or Register  to view this content.
    Last edited by kalak; 06-16-2015 at 04:56 AM.

+ 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. [SOLVED] Remove duplicate characters from a text string in a cell
    By sam99 in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 09-22-2020, 06:10 PM
  2. [SOLVED] Count characters in a string
    By cocacrave in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2015, 12:27 AM
  3. [SOLVED] Removing duplicate characters from string
    By RaydenUK in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-09-2015, 02:49 PM
  4. Formula to Count Duplicate Characters
    By da80th in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 12-31-2012, 10:19 PM
  5. Count unique characters in a string
    By yelkus in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-25-2007, 11:46 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