+ Reply to Thread
Results 1 to 8 of 8

Macro to count a specific substring within a string

  1. #1
    Registered User
    Join Date
    04-28-2015
    Location
    U.S.
    MS-Off Ver
    2007
    Posts
    41

    Talking Macro to count a specific substring within a string

    Hello All,

    I'm in need of of a macro that can count certain characters within a string of selected cells.

    Thanks for any assistance.

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Macro to count a specific substring within a string

    Is the list of characters limited?
    Can you prepare a short sample.
    - Battle without fear gives no glory - Just try

  3. #3
    Registered User
    Join Date
    04-28-2015
    Location
    U.S.
    MS-Off Ver
    2007
    Posts
    41

    Re: Macro to count a specific substring within a string

    Unlimited list of characters text or numbers

    Example
    wdfrt2u7k2y
    nxwrv132nxlyeu09
    tnb5sx7744477qzn

    Then used the macro code to count how may times the number 2 appeared in the list,
    or how many times nx appeared in the list
    or how may times the number 77 appeared in the list.

    This code with a active button on the sheet would help greatly.

    Thanks again for your assistance.

  4. #4
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Macro to count a specific substring within a string

    maybe UDF
    Please Login or Register  to view this content.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    or
    Please Login or Register  to view this content.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by nilem; 05-30-2015 at 09:16 AM. Reason: add option

  5. #5
    Registered User
    Join Date
    04-28-2015
    Location
    U.S.
    MS-Off Ver
    2007
    Posts
    41

    Re: Macro to count a specific substring within a string

    Ok, if i have done anything that has offended you then i'm sorry, but there is no need for this kind of attitude.

    Thanks for your help all the same.

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Macro to count a specific substring within a string

    VBA isn't needed.
    If you have your data in A1:A10 and the string you want to count in B1, then the formula
    =(SUMPRODUCT(LEN(A1:A10)-LEN(SUBSTITUTE(A1:A10,B1,""))))/LEN(B1)

    will return the number sought.

    Note that "777" is counted as having one "77" and "7777" has two.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  7. #7
    Registered User
    Join Date
    04-28-2015
    Location
    U.S.
    MS-Off Ver
    2007
    Posts
    41

    Re: Macro to count a specific substring within a string

    Thanks for the help on this problem.
    Just what i needed! and if I'm not stating my problem on the post correctly i apologize, I'm a newbie.

  8. #8
    Registered User
    Join Date
    04-28-2015
    Location
    U.S.
    MS-Off Ver
    2007
    Posts
    41

    Smile Re: Macro to count a specific substring within a string

    Thanks for the help on this problem.
    Just what i needed! and if I'm not stating my problem on the post correctly i apologize, I'm a newbie.

+ 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. Replies: 3
    Last Post: 09-07-2014, 12:25 AM
  2. [SOLVED] Copy a substring from a string
    By raul09 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-02-2013, 12:53 AM
  3. Finding a substring within a string
    By Michael D in forum Excel General
    Replies: 7
    Last Post: 02-21-2013, 04:01 PM
  4. Searching for a substring in a string
    By 1rovilla in forum Excel General
    Replies: 3
    Last Post: 05-07-2010, 08:17 PM
  5. Searching a String for a Specific Substring
    By ExcelTip in forum Tips and Tutorials
    Replies: 0
    Last Post: 08-23-2005, 04: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