Hi,
I have 2 columns of Names. Column A has 1034 names and Column B has 4500 names.
I would like to have a code that checks if the names in column A match any names in Column B.
If it finds Exact Match - Make the cell green.
If it finds Match but the case is not matching - make it Blue.
If no matches found - Make it Red.
Regards,
Vedaanth
VBA Code to compare 2 column and find match (including case)
-
- NewLounger
- Posts: 15
- Joined: 20 Oct 2016, 09:50
-
- Administrator
- Posts: 78675
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: VBA Code to compare 2 column and find match (including c
Select the names in column A. In the following, I will assume that the selection begins in cell A2 and that A2 is the active cell within the selection.
Set the background color to red - this will be the default (no match).
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
=ISNUMBER(MATCH(A2,$B$2:$B$4500,0))
Here, A2 is the active cell, and $B$2:$B$4500 is the range with names in column B. The $ in $B$2:$B$4500 are important.
Click Format...
Activate the Fill tab.
Select blue, then click OK.
Click OK again to apply the rule.
Repeat the above steps to create a conditional formatting rule, but this time with the formula
=ISNUMBER(MATCH(TRUE,EXACT(A2,$B$2:$B$4500),0))
and with green as color.
Set the background color to red - this will be the default (no match).
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
=ISNUMBER(MATCH(A2,$B$2:$B$4500,0))
Here, A2 is the active cell, and $B$2:$B$4500 is the range with names in column B. The $ in $B$2:$B$4500 are important.
Click Format...
Activate the Fill tab.
Select blue, then click OK.
Click OK again to apply the rule.
Repeat the above steps to create a conditional formatting rule, but this time with the formula
=ISNUMBER(MATCH(TRUE,EXACT(A2,$B$2:$B$4500),0))
and with green as color.
Best wishes,
Hans
Hans
-
- NewLounger
- Posts: 15
- Joined: 20 Oct 2016, 09:50
Re: VBA Code to compare 2 column and find match (including c
Thank you so much.
I will try this and come back.
I will try this and come back.
-
- Administrator
- Posts: 12633
- Joined: 16 Jan 2010, 15:49
- Location: London, Europe
Re: VBA Code to compare 2 column and find match (including c
I'm a lot slower than Hans, but here is an alternative solution that you could try...
You do not have the required permissions to view the files attached to this post.
StuartR