+ Reply to Thread
Results 1 to 10 of 10

Search multiple ranges for duplicates

  1. #1
    Registered User
    Join Date
    10-19-2016
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    5

    Search multiple ranges for duplicates

    Hello,

    I'm trying to search multiple ranges for duplicates, and then display a message box if a duplicate is found. I'm highlighting duplicates via conditional formatting as a backup, but I need a message box too.

    The data that I'm trying to check is located in J4:J15, J20:J34, and AF4:AF28. The cells contain event names, and I can't allow duplicate events. If a user types an event name into any of these fields that already exists, I need a message box to appear with a warning. I've seen plenty of code to check one entire column for duplicates, or one range, but I haven't been able to get anything to work for multiple ranges. Can anyone help me out?

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Search multiple ranges for duplicates

    It should be straightforward to adapt code covering a single range. Can you post something you've tried?

  3. #3
    Registered User
    Join Date
    10-19-2016
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    5

    Re: Search multiple ranges for duplicates

    Here's one that I tried, though it's not my favorite. I didn't like this one because, aside from being unable to make it work for multiple ranges, it brings up two message boxes every time, instead of one. I'm not sure why.

    Please Login or Register  to view this content.
    I've tried simply editing the range to read "J4:J15,J20:J34,AF4:AF28" but it gives me a type mismatch error.

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Search multiple ranges for duplicates

    It fires twice because the duplicate value will be found twice (or more). Just to be clear, are you checking for duplicates over the whole of the three ranges?

  5. #5
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Search multiple ranges for duplicates

    Does this help ?

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-19-2016
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    5

    Re: Search multiple ranges for duplicates

    Ah, that makes sense. Do you have a suggestion on how to avoid the multiple firings?

    Yes, I need it to check to see if any of the values in these three ranges are the same, and throw an error if so. But only these ranges, not the entire columns.

  7. #7
    Registered User
    Join Date
    10-19-2016
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    5

    Re: Search multiple ranges for duplicates

    No, that doesn't help, thanks though. I actually tried what you had, and changed it to see if it made a difference. I've tried having this as a separate sub and doing it withing the worksheet_change, and neither makes a difference either.

  8. #8
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Search multiple ranges for duplicates

    Try this
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-19-2016
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    5

    Re: Search multiple ranges for duplicates

    That seems to work perfectly, thank you!!

  10. #10
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Search multiple ranges for duplicates

    My pleasure. Actually not quite as straightforward as I originally imagined!

+ 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. Search function with multiple dynamic named ranges
    By T86157 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 09-14-2015, 09:27 PM
  2. [SOLVED] Set VBA search function to only search one row and also not show duplicates?
    By TomToms in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-05-2014, 04:00 PM
  3. Replies: 5
    Last Post: 05-04-2014, 10:56 AM
  4. [SOLVED] VBA Macro to find Duplicates using Ranges
    By Kazper in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-09-2013, 02:13 AM
  5. [SOLVED] Highlighting duplicates between 2 ranges
    By Nigel in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-13-2013, 01:52 AM
  6. Eliminating duplicates within certain date ranges
    By SymphonyTomorrow in forum Excel General
    Replies: 1
    Last Post: 11-19-2011, 06:31 AM
  7. Union Ranges and remove duplicates
    By hydrojoe11 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-04-2008, 05:28 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