# Microsoft Office Application Help - Excel Help forum > Excel Programming / VBA / Macros >  >  Comparing values in two columns, and highlight if not equal

## vmc62

Hi all:


I thank all of you for your previous help in other threads.

I have a simple macro problem. I have two columns (i.e.  Columns A  &  E) with values than can be either numbers or strings.

I would like to know of a macro that can compare both columns to see is the values are equal, and if they are not, it would highlight the value in column B (the would be the wrong value) and would do this for several rows (a number of rows I can change when I use this macro in different sheets)

Thank you all for your help

----------


## NBVC

You can use Conditional Formatting for this....

Select column B and go to Format|Conditional Formatting

Cell Value Is >> Equal to >> =A1

Click Format and choose the highlight colour from Pattern tab.

----------


## vmc62

Hi NBVC:

Thanks for the response. 

I made a mistake in my previous post. "I'm comparing columns B & E, and if the values in each row are not the same (number or strings),  the color of the cell for that* value in Column B* should change to red (or any other color)". 

I could use Conditional Formatting as you mentioned, but I need a macro because this is actually a file I'll send to a friend who only needs to click on button, and the process is done automatically. Also I would like to see how is that done using VB code so I can learn a little bit more of Excel Macro and probably tweak it later on for a little different scenario.

If you (or anyone) could help me with this I'd appreciate it.

Thanks

----------


## vmc62

If somebody could help me with this question I'd appreciate it.


Thanks  :Smilie:

----------


## SOS

Hi vmc62,

This code will work down Col B, compare its value with Col E and if the same will turn the cell in Col B red.




```
Please Login or Register  to view this content.
```


Does that do what you want?

----------


## ptm0412

You can use Conditional Formatting for this. Change a little the condition in NBVC's post:

Formula Is>> =A1<>E1

And change the format such as fill color

----------

