Results 1 to 14 of 14

Using Instr to find duplicate strings in a range. Much pain.

Threaded View

Sc0ut Using Instr to find duplicate... 03-08-2015, 08:16 AM
Jakobshavn Re: Using Instr to find... 03-08-2015, 08:35 AM
Sc0ut Re: Using Instr to find... 03-08-2015, 08:38 AM
Jakobshavn Re: Using Instr to find... 03-08-2015, 09:06 AM
Sc0ut Re: Using Instr to find... 03-08-2015, 09:09 AM
Norie Re: Using Instr to find... 03-08-2015, 09:13 AM
Sc0ut Re: Using Instr to find... 03-08-2015, 09:25 AM
Sc0ut Re: Using Instr to find... 03-08-2015, 09:18 AM
Norie Re: Using Instr to find... 03-08-2015, 09:31 AM
Sc0ut Re: Using Instr to find... 03-08-2015, 09:45 AM
Sc0ut Re: Using Instr to find... 03-08-2015, 09:58 AM
Norie Re: Using Instr to find... 03-08-2015, 09:53 AM
Sc0ut Re: Using Instr to find... 03-08-2015, 09:54 AM
Norie Re: Using Instr to find... 03-08-2015, 09:59 AM
  1. #1
    Registered User
    Join Date
    08-04-2013
    Location
    Brisbane
    MS-Off Ver
    Excel for Mac 2021
    Posts
    97

    Using Instr to find duplicate strings in a range. Much pain.

    Hello everyone,

    I'm really struggling with this one. There must be a simple way to get this function to work. I have been trying for hours but I'm not having any joy.

    I simply want to stop two of the same names being entered in a range.

    Here is what I have so far.

    Public Function CompareNames(Rng1 As Range)
    
    CompareNames = Rng1
    
    Dim Cell As Range
    Dim TempString As String
    
    For Each Cell In Rng1
        If Cell.Value = "" Then
            GoTo ParseString
        End If
        TempString = TempString & Cell.Value & ";" & " "
    Next Cell
    
    ParseString:
    Dim Sname As Range
    
    For Each Sname In Rng1
        If Sname.Value = "" Then
            Exit Function
        End If
    
        If InStr(1, TempString, Sname, vbTextCompare) >= 0 Then
    'This is the code that needs some work. I'm not sure how I can get Instr to use the Sname variable (each name in the list) 
    to find duplicates in the TempString variable (all names in the list as one string separated by ";" and space).
            MsgBox "Duplication detected!"
        End If
    
    Next Sname
    
    End Function
    I still can't get find a way to get the function to use Instr to find a duplication. The Instr finds the name that I'm using to search the string (the Sname variable), and returns a "true" result (as it has found the match). Obviously this is a problem as I only want the Instr to give a "true" result when it finds more than one of the same name.

    Any help would be greatly appreciated.
    Last edited by Sc0ut; 03-08-2015 at 08:22 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. InStr Function: Can it evaluate strings in a cell?
    By WmBarth in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-15-2014, 03:26 AM
  2. [SOLVED] count strings based on dates if find duplicate consider it one
    By farrukh in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-10-2012, 01:06 AM
  3. Replies: 5
    Last Post: 02-15-2012, 09:57 AM
  4. Find Unique Text Strings in Range
    By AlvaroSiza in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-28-2011, 10:08 AM
  5. Replies: 5
    Last Post: 07-15-2009, 10:59 AM

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