+ Reply to Thread
Results 1 to 14 of 14

Count the number of times a text pattern is used

Hybrid View

  1. #1
    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

  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

    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:
    Sub macro_1()
    Dim count, pattern_array, no_patterns, i
    no_patterns = Round(Evaluate("=SUMPRODUCT((A2:A13000<>"""")/COUNTIF(A2:A13000,A2:A13000&""""))"), 0)
    ReDim pattern_array(1 To no_patterns, 1 To 1)
    For count = 2 To Range("A" & Rows.count).End(xlUp).Row
        If Range("A" & count - 1) <> Range("A" & count) Then i = i + 1
        pattern_array(i, 1) = pattern_array(i, 1) & "," & Range("B" & count)
    Next count
    Range("D2:D" & no_patterns + 1).Value = pattern_array
    With Range("E2:E" & no_patterns + 1)
        .Formula = "=countif(D$2:D$" & no_patterns + 1 & ",D2)"
        .Value = .Value
    End With
    Range("D2:E" & no_patterns + 1).Sort key1:=Range("D2")
    For count = Range("D" & Rows.count).End(xlUp).Row To 2 Step -1
      If Range("D" & count) = Range("D" & count - 1) Then
        Range("D" & count & ":E" & count).Delete xlUp
      Else
        Range("D" & count) = Right(Range("D" & count), Len(Range("D" & count)) - 1)
      End If
    Next
    End Sub

+ 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