+ Reply to Thread
Results 1 to 5 of 5

How to count occurances of a specific character in a range?

  1. #1
    Registered User
    Join Date
    06-18-2008
    Posts
    1

    Question How to count occurances of a specific character in a range?

    Hello everyone,
    Thanks for all the great help on these forum, I've been reading lots and learning from all the great responses. This one seems to elude me.

    I have named a set range equal to cell B8. I want to change the range if cell b8 contains only one hyphen and keep that range if it has 2 and warn if it has more than 2 hyphens.

    so B8 looks usually like " 10-123-01" or "10-123"
    Here is what the pseudo code looks like:

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: How to count occurances of a specific character in a range?

    Hi

    Broadly you could do something like

    Please Login or Register  to view this content.
    This will allow you to set it if it is 1, do nothing if it is 2 or give a warning if it is > 2. You may also want to cover the situation where you have no hyphens in the result.

    HTH

    rylo

  3. #3
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: How to count occurances of a specific character in a range?

    Or

    EDITED POST shg woke me up

    Please Login or Register  to view this content.

    Or better still with shgs' suggestion
    Please Login or Register  to view this content.

    Called with

    Please Login or Register  to view this content.
    or in the worksheet as a UDF
    Please Login or Register  to view this content.
    The code is now a bit more flexible it will count any instances of a string in a string.

    Please Login or Register  to view this content.

    So your code could be on these lines.
    Please Login or Register  to view this content.
    Last edited by Marcol; 06-15-2010 at 04:27 AM. Reason: Engaged mouth before brain was in gear!

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: How to count occurances of a specific character in a range?

    Another way:
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: How to count occurances of a specific character in a range?

    Thanks for wakening me up shg

    I didn't read the question again!!!

    Rather than further clutter the BB I have edited Post #3

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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