+ Reply to Thread
Results 1 to 14 of 14

Count the number of times a text pattern is used

  1. #1
    Registered User
    Join Date
    05-19-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    25

    Count the number of times a text pattern is used

    Hello Forum

    I have a sample spreadsheet which I have simplified into two columns. I need to count the number of times a pattern occurs in column B.
    So from row 2 to row 8 there is a pattern of text C040015,GAXXXX,JABC,JAFA,JALA,JALB,JALC - this repeats itself again row 9-15 and 16 - 22. (total 3 times)

    rows 23 - 28 , 29 - 34 is another pattern C040015,GAXXXX,JABC,JAIA,JALA,JALC occurring twice

    rows 35 - 42 , 43 - 50 another pattern JAAA,JAEA,JAFA,JAHC,JAHD,JALA,JALB,JALC occurring twice

    so for this spreadsheet

    pattern 1 occurs 3 times
    pattern 1 occurs 2 times
    pattern 1 occurs 2 times

    You will note that the only time the pattern can change is when the number changes in column A

    thanks
    David
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Count the number of times a text pattern is used

    I think if you run a macro like this:
    Please Login or Register  to view this content.
    on your example it will put the results you require in columns D and E.

  3. #3
    Registered User
    Join Date
    05-19-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Count the number of times a text pattern is used

    Hi

    It works but produces duplicate values as such
    ,C040015,GAXXXX,JABC,JAFA,JALA,JALB,JALC 3
    ,C040015,GAXXXX,JABC,JAFA,JALA,JALB,JALC 3
    ,C040015,GAXXXX,JABC,JAFA,JALA,JALB,JALC 3
    ,C040015,GAXXXX,JABC,JAIA,JALA,JALC 1
    ,C040015,GAXXXX,JAFA,JALA,JALB,JALC 1
    ,JAAA,JAEA,JAFA,JAHC,JAHD,JALA,JALB,JALC 2
    ,JAAA,JAEA,JAFA,JAHC,JAHD,JALA,JALB,JALC 2


    thanks
    David

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Count the number of times a text pattern is used

    Please Login or Register  to view this content.
    Last edited by ragulduy; 04-07-2014 at 10:34 AM.

  5. #5
    Registered User
    Join Date
    05-19-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Count the number of times a text pattern is used

    Hi

    I still get the same result although this time a vb error "Invalid call procedure or argument"

    thanks
    David

  6. #6
    Registered User
    Join Date
    05-19-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Count the number of times a text pattern is used

    Sorry forgot to mention, the final spreadsheet has 12272 rows on it.
    David

  7. #7
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Count the number of times a text pattern is used

    Hi, I edited the code to fix that soon after posting, try it again now and it should be fine.

  8. #8
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Count the number of times a text pattern is used

    I constructed a chart with the keys in the left column and the patterns as column headers with the totals at the bottom.
    Attached Files Attached Files
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  9. #9
    Registered User
    Join Date
    05-19-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Count the number of times a text pattern is used

    Quote Originally Posted by ragulduy View Post
    Hi, I edited the code to fix that soon after posting, try it again now and it should be fine.
    Hi

    For this I get subscript out of range.
    thanks
    David

  10. #10
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Count the number of times a text pattern is used

    I've just double checked on your example and it runs ok - see attachment with sheet1 as your original data and sheet2 after running the code in module 1.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    05-19-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Count the number of times a text pattern is used

    Yes, I get your example to work, but when I amended the code for extra lines, I get error 400. I have attached the finished spreadsheet.

    thanks
    David
    Attached Files Attached Files

  12. #12
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Count the number of times a text pattern is used

    Hi, there was a problem with the formula to get the number of unique lines (the evaluate bit), it was returning .999999 instead of an integer. If you add a round function it should be ok:
    Please Login or Register  to view this content.

  13. #13
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Count the number of times a text pattern is used

    Sorry, I just noticed in your main examples the patterns do not appear consecutively as they did in their example. You also need to sort the results before going through and deleting duplicates:
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    05-19-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Count the number of times a text pattern is used

    Many thanks for your help.
    Issue solved

+ 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 the number of times a particular text appears in group of cells
    By L.LEE in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-29-2013, 04:16 AM
  2. Macro to Count the number of Rows between a text value that occurs mutliple times
    By AdamMoffitt in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-06-2013, 11:34 AM
  3. Count the number of times a specific text appears in column D
    By jonvanwyk in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-04-2011, 02:02 PM
  4. Counting number of times a Text pattern appeared in a range
    By khalidawan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-13-2008, 05:35 AM
  5. [SOLVED] how do I count the number of times text in column A matches text i
    By Sheila in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-16-2005, 06:25 PM

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