SOLVED

Compare two columns and highlight matches

%3CLINGO-SUB%20id%3D%22lingo-sub-1652284%22%20slang%3D%22en-US%22%3ECompare%20two%20columns%20and%20highlight%20matches%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1652284%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EHello%20everyone%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%3CSPAN%3Ei'm%20searching%20how%20to%20Compare%20two%20columns%20and%20highlight%20matches%20(1%20on%201)%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3Ethere%20is%20many%20different%20ways%20but%20what%20i%20want%20is%20to%20highlight%20one%20cell%20if%20there%20is%20only%201%20cell%20that%20contains%20the%20same%20value%20on%20the%20other%20column%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3Efor%20example%20%3A%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3Ewith%20the%20methods%20i%20use%20the%20%22126%22%20value%20highlighted%20twice%20in%20the%20first%20column%20even%20that%20there%20is%20one%20in%20the%20second%20one%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Example1.jpg%22%20style%3D%22width%3A%20735px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F217500iBAFD8EFC464F8408%2Fimage-dimensions%2F735x413%3Fv%3D1.0%22%20width%3D%22735%22%20height%3D%22413%22%20title%3D%22Example1.jpg%22%20alt%3D%22Example1.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eand%20what%20i%20want%20%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Example2.jpg%22%20style%3D%22width%3A%20960px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F217501iB966087D28490301%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Example2.jpg%22%20alt%3D%22Example2.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Ei%20hope%20i've%20explained%20it%20well%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%20.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1652284%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1652686%22%20slang%3D%22en-US%22%3ERe%3A%20Compare%20two%20columns%20and%20highlight%20matches%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1652686%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F788581%22%20target%3D%22_blank%22%3E%40Assino960%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20find%20below%20the%20logic%20which%20you%20need%20to%20paste%20the%20conditional%20formatting%20using%20formula%3C%2FP%3E%3CP%3Emake%20sure%20you%20select%20the%20range%20correctly.%20I'm%20attaching%20the%20sample%20sheet%20for%20your%20ready%20reference.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Snag_4c0454e8.png%22%20style%3D%22width%3A%20371px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F217512i5C5BBB2E87256758%2Fimage-dimensions%2F371x376%3Fv%3D1.0%22%20width%3D%22371%22%20height%3D%22376%22%20title%3D%22Snag_4c0454e8.png%22%20alt%3D%22Snag_4c0454e8.png%22%20%2F%3E%3C%2FSPAN%3E%E2%80%83%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3ELogic%2001%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%3DISNA(MATCH(B1%2C%24A%241%3A%24A%246%2C0))%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%E2%80%83%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Snag_4c04737d.png%22%20style%3D%22width%3A%20603px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F217513i7C781F32AEA86DC0%2Fimage-dimensions%2F603x259%3Fv%3D1.0%22%20width%3D%22603%22%20height%3D%22259%22%20title%3D%22Snag_4c04737d.png%22%20alt%3D%22Snag_4c04737d.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3ELogic%2002%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%3DNOT(ISNA(MATCH(B1%2C%24A%241%3A%24A%246%2C0)))%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Snag_4c04faec.png%22%20style%3D%22width%3A%20603px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F217514iD54F90EADE082DD2%2Fimage-dimensions%2F603x259%3Fv%3D1.0%22%20width%3D%22603%22%20height%3D%22259%22%20title%3D%22Snag_4c04faec.png%22%20alt%3D%22Snag_4c04faec.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ERegards%2C%20Faraz%20Shaikh%20%7C%20MCT%2C%20MIE%2C%20MOS%20Master%2C%20Excel%20Expert%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CEM%3E%3CFONT%20color%3D%22%23808080%22%3EIf%20you%20find%20the%20above%20solution%20resolved%20your%20query%20don't%20forget%20mark%20as%26nbsp%3B%3CSPAN%3EOfficial%2FBest%20Answer%26nbsp%3Bto%20help%20the%20other%20members%20find%20it%20more%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FEM%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1652699%22%20slang%3D%22en-US%22%3ERe%3A%20Compare%20two%20columns%20and%20highlight%20matches%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1652699%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F788581%22%20target%3D%22_blank%22%3E%40Assino960%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20do%20this%20with%20conditional%20formatting.%3C%2FP%3E%0A%3CP%3EInsert%20a%20row%20above%20the%20data%20to%20make%20it%20easier.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESelect%20A2%3AA7.%3C%2FP%3E%0A%3CP%3EOn%20the%20Home%20tab%20of%20the%20ribbon%2C%20select%20Conditional%20Formatting%20%26gt%3B%20New%20Rule...%3C%2FP%3E%0A%3CP%3ESelect%20'Use%20a%20formula%20to%20determine%20which%20cells%20to%20format'.%3C%2FP%3E%0A%3CP%3EEnter%20the%20formula%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3DAND(ISNUMBER(MATCH(A2%2C%24B%242%3A%24B%247%2C0))%2CCOUNTIF(A%241%3AA1%2CA2)%3D0)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EClick%20Format...%3C%2FP%3E%0A%3CP%3ESpecify%20the%20desired%20font%20color%20and%2For%20fill%20color.%3C%2FP%3E%0A%3CP%3EClick%20OK%2C%20then%20click%20OK%20again.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDo%20the%20same%20for%20B2%3AB7%2C%20but%20with%20the%20formula%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3DAND(ISNUMBER(MATCH(B2%2C%24A%242%3A%24A%247%2C0))%2CCOUNTIF(B%241%3AB1%2CB2)%3D0)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1653196%22%20slang%3D%22en-US%22%3ERe%3A%20Compare%20two%20columns%20and%20highlight%20matches%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1653196%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F156456%22%20target%3D%22_blank%22%3E%40Faraz%20Shaikh%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EHi.%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3Ethanks%20for%20replying%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3Ei%20appreciate%20your%20help%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EBut%20when%20i%20use%20your%20method%20on%20a%20large%20data%20i%20don't%20get%20the%20result%20i%20want%2C%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Ewhat%20i%20want%20as%20result%20that%20the%20sum%20of%20highlighted%20cells%20in%20A%20%3D%20to%20the%20highlighted%20cells%20in%20B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E(if%20there%20is%202%20cells%20that%20contains%20%22x%22%20in%20column%201%2C%20and%203%20%22x%22%20in%20column%202%2C%20i%26nbsp%3B%20want%20to%20highlight%20two%20cells%20in%20each%20column).%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1653318%22%20slang%3D%22en-US%22%3ERe%3A%20Compare%20two%20columns%20and%20highlight%20matches%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1653318%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EHi.%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3Ethanks%20for%20replying%3A)%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3Ei%20appreciate%20your%20help%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EBut%20when%20i%20use%20your%20method%20on%20a%20large%20data%20i%20don't%20get%20the%20result%20i%20want%2C%20and%20also%20tehere%20is%20a%20lot%20of%20matches%20that%20are%20not%20highlighted.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Ewhat%20i%20want%20as%20result%20that%20the%20sum%20of%20highlighted%20cells%20in%20A%20%3D%20to%20the%20highlighted%20cells%20in%20B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E(if%20there%20is%202%20cells%20that%20contains%20%22x%22%20in%20column%201%2C%20and%203%20%22x%22%20in%20column%202%2C%20i%26nbsp%3B%20want%20to%20highlight%20two%20cells%20in%20each%20column).%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hello everyone


i'm searching how to Compare two columns and highlight matches (1 on 1)
there is many different ways but what i want is to highlight one cell if there is only 1 cell that contains the same value on the other column
for example :

with the methods i use the "126" value highlighted twice in the first column even that there is one in the second one

 

Example1.jpg

and what i want :

Example2.jpg

i hope i've explained it well .

6 Replies

Hi @Assino960 

 

Please find below the logic which you need to paste the conditional formatting using formula

make sure you select the range correctly. I'm attaching the sample sheet for your ready reference.

 

Snag_4c0454e8.png

 

 

Logic 01

 

=ISNA(MATCH(B1,$A$1:$A$6,0))

 

Snag_4c04737d.png

 

Logic 02

 

=NOT(ISNA(MATCH(B1,$A$1:$A$6,0)))

 

 

Snag_4c04faec.png

 

Regards, Faraz Shaikh | MCT, MIE, MOS Master, Excel Expert

If you find the above solution resolved your query don't forget mark as Official/Best Answer to help the other members find it more

@Assino960 

You can do this with conditional formatting.

Insert a row above the data to make it easier.

 

Select A2:A7.

On the Home tab of the ribbon, select Conditional Formatting > New Rule...

Select 'Use a formula to determine which cells to format'.

Enter the formula

 

=AND(ISNUMBER(MATCH(A2,$B$2:$B$7,0)),COUNTIF(A$1:A1,A2)=0)

 

Click Format...

Specify the desired font color and/or fill color.

Click OK, then click OK again.

 

Do the same for B2:B7, but with the formula

 

=AND(ISNUMBER(MATCH(B2,$A$2:$A$7,0)),COUNTIF(B$1:B1,B2)=0)

@Faraz Shaikh 

Hi.
thanks for replying
i appreciate your help

But when i use your method on a large data i don't get the result i want, 

what i want as result that the sum of highlighted cells in A = to the highlighted cells in B

(if there is 2 cells that contains "x" in column 1, and 3 "x" in column 2, i  want to highlight two cells in each column).

 

@Hans Vogelaar 

Hi.
thanks for replying
i appreciate your help

But when i use your method on a large data i don't get the result i want, and also tehere is a lot of matches that are not highlighted.

what i want as result that the sum of highlighted cells in A = to the highlighted cells in B

(if there is 2 cells that contains "x" in column 1, and 3 "x" in column 2, i  want to highlight two cells in each column).

Best Response confirmed by Assino960 (Occasional Contributor)
Solution

@Assino960  well you changed the rules a little. lol.  As for the errors in @Hans Vogelaar method that was because you had an error in the formula in that sheet.  You probably shifted the sheet / target range because instead of A$1:A1 you had A$2:A2 and instead of referencing A2 it was looking at A3, which is what threw everything off.  That all said I think this set of conditional formatting formulas might be what you want:

=COUNTIF(A$2:A2,A2)<=COUNTIF(B:B,A2)

=COUNTIF(B$2:B2,B2)<=COUNTIF(A:A,B2)

see attached sheet.

Hi,

thanks all of you for helping me out I really appreciate it :).