简体   繁体   中英

Excel highlight duplicates in 2 columns, ignoring same row

I have 2 non adjacent text columns that I wish to compare. There may be duplicates in both columns but if they are not on the same row I need them to be highlighted in both columns. In the example below, Barry and Larry would both be highlighted in Columns A & C.

     | Col A. |  Col B.  |    Col C.   
Row1.| Harry  | London   |   Harry
Row2.| Barry  | Paris    |   Larry
Row3.| Larry  | New York |   Barry
Row4.| Gary   | Munich   |   Tom

If the same names are not aligned in the same row I would then cut and paste the offenders to resolve the problem. In this case the Barry in column C would be cut and inserted into row 2, forcing Larry down into row 3. Nothing would then be highlighted.
I guess it is a conditional formatting problem but I can't get a formula to work. I would appreciate some ideas.

So if I am understanding you correctly, you want to:

1) Find duplicates and highlight them

2) Move the offenders

Is there some reason this needs to be two parts? For moving the offenders I would run 2 loops, one to loop through the cells in column A, for each cell in column AI would loop through column C until I find the match, cut it, and paste it into the range that is two columns over from the current cell you are comparing in the first loop. you can use a range offset to find the right place to paste the name in column C.

Arrays would do this more quickly, so if you have a large number of records it would be worth looking in to.

You can use a dictionary object to accomplish both steps more easily, you can use dict.exists(value) to determine if a match exists and use those addresses for formatting, a quick google will help you with how to use them.

Honestly this seems like a homework problems so that's as far as I will go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM