Question : SUMPRODUCT fn with nested IF statements

I have a spreadsheet containing names and email addresses.  Because of the way the spreadsheet is exported from our management system, there can be more than one line for each person.  I won't explain why that is, but it is.  So John Doe might be repeated 10 times in each of 10 lines.  Then, each John Doe record has 4 separate columns for email addresses, as in Email1, Email2, Email3, etc.  

I need to weed out duplicates, so I wrote a formula which tests whether whether the email addresses in each of the 4 columns has occurred before, and if so indicate with "duplicate."    If not a duplicate put "OK" in the cell.  I can then filter to show only the "OK's."  The screen shot below shows the results of the formula. As you can see, the formula actually works fine.  

So why the question?  Well, the formula is so long and complicated and has so many nested if statements, that when I copy it down thousands of rows, it brings Excel nearly to a halt while it calculates everything.  

I'm wondering if someone has a more elegant formula or way to get the same thing without making Excel do so much thrashing.

The formula in each cell of column H has something like the following:

=IF(SUMPRODUCT((IF(COUNTIF(D$2:D4,D4)>1,1,0)*(IF(COUNTIF(E$2:E4,E4)>1,1,0)*(IF(COUNTIF(F$2:F4,F4)>1,1,0)*(IF(COUNTIF(G$2:G4,G4)>1,1,0))))))=1,"Duplicate","OK")

Nasty, I know.  Essentially, there are 4 individual tests using IF(COUNTIF()) functions to see if the email address in columns D, E, F and G have occurred before, and they evaluate to a 1 if it has and 0 if it hasn't.  Each of those inner duplicate tests are multiplied together using the SUMPRODUCT fn.  If SUMPRODUCT evaluates to a 1, I know a duplicate exists and, using the outmost IF statement, it returns the string "Duplicate."  If it evaluates to 0 then it returns "OK."

Like I said, it works well, but as the formula is copied down the column, the inner COUNTIFs are working on longer and longer ranges of numbers.  The very bottom cell of column H has 4 COUNTIF(D$2:D13287,D13287)>1,1,0) inner statements.  

Soooo.... is there a better way to achieve the same result?

Answer : SUMPRODUCT fn with nested IF statements

Sorry...again...

Place this formula in cell I2:

=D2&"|"&E2&"|"&F2&"|"&G2

Copy I2 to I3.

Place this formula in cell H3:

=IF(COUNTIF(I$2:I2,"="&D3&"|"&E3&"|"&F3&"|"&G3)>0,"Duplicate","OK")

Copy H3:I3 down as far as needed.

Kevin
Random Solutions  
 
programming4us programming4us