Microsoft Excel - compare between two columns row by row using macro

Asked By Nurah
05-Mar-11 05:19 AM

Hi All,

 I need to compare 2 columns using macro vb row by row. 

the result of the comparison well be as alert

e.g.

Column 1 :

Row 1: 1
Row 2: 2
Row 3: 3
Row 4: 4

Column 2:
Row 1: 2
Row 2: 2
Row 3: 3
Row 4: 5
I need  compare row 1 of column 1 with Row 1 of Column 2.

If any item in column 2= (column+1) . the raw color should be change



  Jackpot . replied to Nurah
06-Mar-11 11:42 PM
Hi Nurah

You may use conditional formatting.

1. Select the cell/Range (say A1:B10). Please note that the cell reference A1 mentioned in the formula is the active cell in the selection. Active cell will have a white background even after selection
2. From menu Format>Conditional Formatting>
3. For Condition1>Select 'Formula Is' and enter the below formula
=$B1=$A1+1

4. Click Format Button>Pattern and select your color (say Red)
5. Hit OK

PS: If you are using XL2007 Goto Home tab>Styles>Conditional Formatting>Manage rules>New rule>Use a formula to determine which cells to format. Enter the formula in the box below.



  Satish Kumar replied to Nurah
07-Mar-11 10:22 AM
Hi,
you can use below code for formatting the entire ROW based on two matched cells value

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
For Each cell In Range("$B1:$B7")
If cell.Value = Sheet1.Cells(cell.Row, 1).Value Then
cell.EntireRow.Interior.ColorIndex = 40
Else
cell.EntireRow.Interior.ColorIndex = Default
End If
Next
End Sub

hope this is useful to you.
Create New Account
help
Conflict with Valid Range Reference Error in Microsoft Excel 2007 Excel Hi, While converting the Macros enabled Microsoft Excel 2003 to Microsoft Excel 2007 format, I am getting the following Conflict with Valid Range Reference Error. After clicking
Enregistrer dbf sous excel 2007 Excel Bonjour la Communaut??, Comment r??ussir ?? enregistrer un format dbf sous excel 2007? Merci pour vos conseils Bernie Excel - French Discussions Microsoft Excel (1) Excel 2003 (1) Excel 2007 (1) DBASE (1) Enregistrer (1) Communaut (1) Conseils (1
What are the differences between excel 2000 & excel 2007? Excel We're trying to decide if it would be beneficial to upgrade from excel 2000 to excel 2007. What are the differences between excel 2000 & excel 2007? Excel Miscellaneous Discussions Microsoft Excel (1) Excel 2007 (1) BA597438D5D2 (1) Previews
Deleating All Selected Data Excel 2007 Excel Excel 2007 (What worked for Excel 2003 makes 2007 crash). I have run Microsoft Office Diagnostics and it can not identify any problems) When I try to delete data
SQL plus de Inclure les noms de champ dans SQL EXcel 2007 Excel Bonjour, Nous venons de miger de Microsoft Excel 2003 vers Microsoft Excel 2007. Dans la version Excel 2003, on avait avec clic droit sur une plage de donnÃ