+ Reply to Thread
Results 1 to 14 of 14

Looping While Checking for Duplicate cells

  1. #1
    Registered User
    Join Date
    09-10-2014
    Location
    OKC, OK
    MS-Off Ver
    2010
    Posts
    18

    Post Looping While Checking for Duplicate cells

    I would like to run a macros that compares two rows at a time and compares columns G, S, and T. If column G is blank in either row; the row with the blank Column G is highlighted in red.

    I would like this to run starting with row 2 and compare the row beneath until the last row with data.

    For example, compare any rows that have the same values in columns S and T; this could be Row 2 and Row 3. It could be Rows 2, 3, and 4. If Row 2 and Row 3 have the same values in columns S and T, but column G has any value in one row, but column G does not have a value in the other row, highlight the row with the blank column G, then, this repeats for the rest of the spreadsheet.

    If Row 5 does not have duplicates of columns S and T compared to Row 2, the process restarts and compares Row 5 with the rows beneath it.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Looping While Checking for Duplicate cells

    I think you could do this with Conditional Formatting

    Highlight your data from rows 2 to the last used row and enter in this CF formula.

    =AND($G2="", COUNTIFS($G$2:$G$1000, "<>", $S$2:$S$1000, $S2, $T$2:$T$1000, $T2))

    Make sure the 1000 in the formula goes up to or beyond the last used row of your data
    Last edited by AlphaFrog; 05-03-2017 at 03:12 PM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    09-10-2014
    Location
    OKC, OK
    MS-Off Ver
    2010
    Posts
    18

    Re: Looping While Checking for Duplicate cells

    1.PNG


    Thank you for your help on this! The way it would need to highlight would be the row that was highlighted in the example I uploaded.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Looping While Checking for Duplicate cells

    I suggested a solution in post #2. Did you try it? Do you need help with Conditional Formatting?

  5. #5
    Registered User
    Join Date
    09-10-2014
    Location
    OKC, OK
    MS-Off Ver
    2010
    Posts
    18

    Re: Looping While Checking for Duplicate cells

    2.PNG

    Yes, I tried your solution. Thank you!
    With your solution, Rows 2, 3, 6, and 7 were highlighted. I only needed Row 3 highlighted. I have attached an updated example showing the rows that were highlighted (red) and the row that I needed highlighted (yellow).

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Looping While Checking for Duplicate cells

    It looks like you put the conditional formatting formula starting in row 1. That would mess up the formula.

    Select your data rows starting with rows 2 to your last used row and then apply the CF formula.

  7. #7
    Registered User
    Join Date
    09-10-2014
    Location
    OKC, OK
    MS-Off Ver
    2010
    Posts
    18

    Re: Looping While Checking for Duplicate cells

    I ran the formula from row 2 as directed. Rows 2, 6, 7, and 18 were highlighted, but shouldn’t have been.

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Looping While Checking for Duplicate cells

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  9. #9
    Registered User
    Join Date
    09-10-2014
    Location
    OKC, OK
    MS-Off Ver
    2010
    Posts
    18

    Re: Looping While Checking for Duplicate cells

    Example is attached!
    Last edited by khemistry1911; 05-04-2017 at 03:04 PM.

  10. #10
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Looping While Checking for Duplicate cells

    See attached with the CF formulas added.

    Row 15 doesn't seem to have a match.

    I have an older version of Excel which doesn't have the COUNTIFS function so I used SUMPRODUCT instead which can do the same thing. You could use either formula. I haven't changed anything from what I suggested to you, and I don't know why it didn't work before.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    09-10-2014
    Location
    OKC, OK
    MS-Off Ver
    2010
    Posts
    18

    Re: Looping While Checking for Duplicate cells

    I have attached a new Example file with an added After_CF tab so you can see how the formula =AND($G2="", COUNTIFS($G$2:$G$2500, "<>", $S$2:$S$2500, $S2, $T$2:$T$2500, $T2)) affects the data. Also, I was unable to open the file you attached.
    Last edited by khemistry1911; 05-04-2017 at 03:05 PM.

  12. #12
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Looping While Checking for Duplicate cells

    Try this cf formula.

    = AND($G2="",SUMPRODUCT(($G$2:$G$2500<>"")*($S$2:$S$2500=$S2)*($T$2:$T$2500=$T2)))

  13. #13
    Registered User
    Join Date
    09-10-2014
    Location
    OKC, OK
    MS-Off Ver
    2010
    Posts
    18

    Re: Looping While Checking for Duplicate cells

    It worked like a charm! What did you change??

  14. #14
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Looping While Checking for Duplicate cells

    Quote Originally Posted by khemistry1911 View Post
    It worked like a charm! What did you change??
    The column G criteria in the COUNTIFS function wasn't correct. If column G is numbers or blanks, you could use this...

    =AND($G2="", COUNTIFS($G$2:$G$1000, ">0", $S$2:$S$1000, $S2, $T$2:$T$1000, $T2))

+ 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. Duplicate checking
    By JoshJ in forum Excel General
    Replies: 3
    Last Post: 12-09-2013, 06:46 PM
  2. [SOLVED] Duplicate Checking
    By chris.slater in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 01-31-2013, 02:28 PM
  3. Reverse duplicate checking
    By SinrG202 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-05-2012, 01:17 AM
  4. Duplicate Checking
    By niladri20005 in forum Excel General
    Replies: 1
    Last Post: 07-15-2011, 02:48 PM
  5. Checking cells for duplicate references
    By mpkavanagh in forum Excel General
    Replies: 1
    Last Post: 01-10-2011, 04:35 PM
  6. User Input Checking & Formula Looping
    By flebber in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-12-2010, 09:12 PM
  7. Checking existing data for pairs and looping
    By cheeseslice in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-15-2008, 03:18 PM
  8. looping when checking isdate
    By april27 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-16-2006, 08:50 AM

Tags for this Thread

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