+ Reply to Thread
Results 1 to 14 of 14

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

  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.

    Please Login or Register  to view this content.
    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.

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

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

    Begin by replacing:

    Please Login or Register  to view this content.
    with

    Please Login or Register  to view this content.
    There may be other problems.
    Gary's Student

  3. #3
    Registered User
    Join Date
    08-04-2013
    Location
    Brisbane
    MS-Off Ver
    Excel for Mac 2021
    Posts
    97

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

    Thanks.

    The range is fed though fine, though.

  4. #4
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

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

    Here is an alternative way to detect duplicates in a Range:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-04-2013
    Location
    Brisbane
    MS-Off Ver
    Excel for Mac 2021
    Posts
    97

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

    Thank you so much! This looks really good. Could you please help me understand how it works?

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

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

    Try using CountIf.

    This formula will return True if any duplicates are found in Rng1.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  7. #7
    Registered User
    Join Date
    08-04-2013
    Location
    Brisbane
    MS-Off Ver
    Excel for Mac 2021
    Posts
    97

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

    This looks excellent. Thanks Norie. You guys make it look so easy! I've been toiling for many, many hours.

  8. #8
    Registered User
    Join Date
    08-04-2013
    Location
    Brisbane
    MS-Off Ver
    Excel for Mac 2021
    Posts
    97

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

    Hey Norrie, with the "DuplicateCheck = True", I can't use the result of this variable (i.e. True or False) outside of this function. Why's might that be? I'm sorry if it's obvious!
    Last edited by Sc0ut; 03-08-2015 at 09:31 AM.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

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

    What do you mean exactly?

    Where/how are you trying to use DuplicateCheck?

    You would use it something like this.
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    08-04-2013
    Location
    Brisbane
    MS-Off Ver
    Excel for Mac 2021
    Posts
    97

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

    When I call the function using this:

    Please Login or Register  to view this content.
    I'm getting a compile error:

    "ByRef argument type mismatch"

    On "Rng"

    In this line:
    Please Login or Register  to view this content.
    Why might this be?

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

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

    How have you declared Rng?

  12. #12
    Registered User
    Join Date
    08-04-2013
    Location
    Brisbane
    MS-Off Ver
    Excel for Mac 2021
    Posts
    97

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

    I just had to Dim it first
    Please Login or Register  to view this content.
    Thank you so much Norri! I can't tell you how helpful this is.

    Could you tell me if there is a to clear the cell that now has the duplicate name entered?

  13. #13
    Registered User
    Join Date
    08-04-2013
    Location
    Brisbane
    MS-Off Ver
    Excel for Mac 2021
    Posts
    97

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

    This does the trick:
    Please Login or Register  to view this content.
    Thank you so much! You and the others have been wonderfully helpful.

  14. #14
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

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

    Where are you using the code?

+ 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. 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