+ Reply to Thread
Results 1 to 3 of 3

VBA to check if "same word" exists in a cell

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-26-2013
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    367

    VBA to check if "same word" exists in a cell

    Hi,

    I just want to check if there is a same word exists in a cell, if there is, B1 should be tagged as "Y" else tagged as "N"

    I have attached my file.

    Thanks in advance gurus!
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    401

    Re: VBA to check if "same word" exists in a cell

    One way would be to treat the contents of the cell as a string.

    Loop through the string, one character at a time. Each time you come to a space, that signifies the end of a word. "Build" your words in this manner and store that word you just found in a one dimensional table.

    After you've stored all of the words in your table, you simply loop through the table, searching it.

    You check Word #1 against Word #2, Word #3, Word #4, etc., thru to the end. If you ever find a match, tag B1 as Yes and exit the loop. You're done.

    Once you get thru to the end, if no match, then Word #1 doesn't equal anything.

    And if so, now you have to check Word #2 against Word #3, Word #4, Word #5, etc., thru to the end. Again, if a match, tag as yes and exit the loop.

    And so on.

    Eventually you will have checked all words against each other.

    There's probably more elegant ways of doing this but this is the first thing that comes to my mind.

    (For someone with 350 posts, I assume you won't have a problem writing this code.)

  3. #3
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: VBA to check if "same word" exists in a cell

    UDF "FiindDupText" given. It is assumed that sl numbers will be there inside the text of the cell (like in your example).
    Code
    Function FindDupText(ByVal Inputval As String)
    
    Dim M As Variant
    Dim T1 As Long, T2 As Long
    
    FindDupText = "N"
    
    M = Split(Inputval, ".")
    
    For T1 = 1 To UBound(M) - 1
    
        For T2 = (T1 + 1) To UBound(M)
        
        If Left(M(T1), InStr(1, M(T1), ":") - 1) = Left(M(T2), InStr(1, M(T2), ":") - 1) Then
        FindDupText = "Y"
        Exit Function
        End If
        
        Next T2
        
    Next T1
    
    End Function
    Attached Files Attached Files

+ 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. Delete entire column if word "False" exists
    By mikey3580 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-09-2014, 02:33 PM
  2. Replies: 5
    Last Post: 01-23-2014, 11:02 AM
  3. [SOLVED] Formula Needed to fill multiple cells with "No" when the word "No" is entered into a cell
    By excelteam777 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-09-2013, 05:36 PM
  4. VBA to check if a .jpg exists in "ThisWorkbook.Path"
    By Rerock in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-30-2013, 04:42 PM
  5. Check if date exists in Named Range "Holiday_List"
    By carsto in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2012, 02:33 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