+ Reply to Thread
Results 1 to 8 of 8

Need to identify repeated text in a string

Hybrid View

  1. #1
    Registered User
    Join Date
    04-09-2013
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2010
    Posts
    17

    Need to identify repeated text in a string

    Hey All,

    I'm thinking I need to go into VBA or macros to get this done, which I don't have a lot of experience in. Here is what I want to identify..

    We have long descriptions tied to products, and we have about 50K products we need to review. I want to find where a word is repeated twice, one right after the other. ie..

    ID,Long Desc
    123456,"This product description has an error error where I need to review the duplicate word"
    456789,"This description is fine and has duplicate words, but not words that are repeated one after the other, and so I don't need to review it"

    Any assistance is much appreciated. Thank you,

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

    Re: Need to identify repeated text in a string

    Perhaps something like

    Dim oneCell as Range
    Dim Words As Variant
    Dim I As Long
    
    For Each oneCell in Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp))
        Words = Split(CStr(oneCell.Value), " ")
    
        For I = 1 to UBound(Words)
            If LCase(Words(I)) = LCase(Words(I-1)) Then
                oneCell.Interior.ColorIndex = 3
                Exit For
            End If
        Next i
    Next oneCell
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    04-09-2013
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Need to identify repeated text in a string

    Quote Originally Posted by mikerickson View Post
    Perhaps something like

    Dim oneCell as Range
    Dim Words As Variant
    Dim I As Long
    
    For Each oneCell in Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp))
        Words = Split(CStr(oneCell.Value), " ")
    
        For I = 1 to UBound(Words)
            If LCase(Words(I)) = LCase(Words(I-1)) Then
                oneCell.Interior.ColorIndex = 3
                Exit For
            End If
        Next i
    Next oneCell
    Thank you for the reply. When I run this one I get an error, Invalid outside proceedure.

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,671

    Re: Need to identify repeated text in a string

    Sub tset()
        Dim r As Range, m As Object
        Columns(1).Font.Bold = False
        With CreateObject("VBScript.RegExp")
            .IgnoreCase = True: .Global = True
            .Pattern = "\b(\S+) \1\b"
            For Each r In Range("a1", Range("a" & Rows.Count).End(xlUp))
                For Each m In .Execute(r.Value)
                    r.Characters(m.firstindex + 1, m.Length).Font.Bold = True
                Next
            Next
        End With
    End Sub

  5. #5
    Registered User
    Join Date
    04-09-2013
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Need to identify repeated text in a string

    Quote Originally Posted by jindon View Post
    Sub tset()
        Dim r As Range, m As Object
        Columns(1).Font.Bold = False
        With CreateObject("VBScript.RegExp")
            .IgnoreCase = True: .Global = True
            .Pattern = "\b(\S+) \1\b"
            For Each r In Range("a1", Range("a" & Rows.Count).End(xlUp))
                For Each m In .Execute(r.Value)
                    r.Characters(m.firstindex + 1, m.Length).Font.Bold = True
                Next
            Next
        End With
    End Sub

    Thanks, this is exactly what I am looking for. After applying this to the data I found that I need an identifier, ideally in another field. I would like to have an identifier to sort or filter by. Is this possible?

    Thanks again. This is going to save an enormous amount of work.

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,671

    Re: Need to identify repeated text in a string

    Do you mean like this?
    Otherwise, need to see how you want it in a sample workbook.
    Sub tset()
        Dim r As Range, m As Object
        Columns(1).Font.Bold = False
        With CreateObject("VBScript.RegExp")
            .IgnoreCase = True: .Global = True
            .Pattern = "\b(\S+) \1\b"
            For Each r In Range("a1", Range("a" & Rows.Count).End(xlUp))
                If .test(r.Value) Then r(, 2).Value = "Dup"
                For Each m In .Execute(r.Value)
                    r.Characters(m.firstindex + 1, m.Length).Font.Bold = True
                Next
            Next
        End With
    End Sub

  7. #7
    Registered User
    Join Date
    04-09-2013
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Need to identify repeated text in a string

    Quote Originally Posted by jindon View Post
    Do you mean like this?
    Otherwise, need to see how you want it in a sample workbook.
    Sub tset()
        Dim r As Range, m As Object
        Columns(1).Font.Bold = False
        With CreateObject("VBScript.RegExp")
            .IgnoreCase = True: .Global = True
            .Pattern = "\b(\S+) \1\b"
            For Each r In Range("a1", Range("a" & Rows.Count).End(xlUp))
                If .test(r.Value) Then r(, 2).Value = "Dup"
                For Each m In .Execute(r.Value)
                    r.Characters(m.firstindex + 1, m.Length).Font.Bold = True
                Next
            Next
        End With
    End Sub
    Perfecto! This is exactly what I needed. I appreciate all the assistance. Have a great day!

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,671

    Re: Need to identify repeated text in a string

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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: 15
    Last Post: 07-29-2014, 02:27 PM
  2. [SOLVED] How to identify repeated/duplicate code with different text
    By mahershams in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 06-09-2014, 07:44 AM
  3. Find last repeated character position from a text string
    By krjoshi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-17-2011, 02:14 PM
  4. poiting a certain number to identify how many time it is repeated
    By spolonova in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 04-02-2011, 03:19 AM
  5. Extract repeated words from Text string
    By Calman in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-14-2007, 10:22 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