macro for same value in 2 different sheets
try this macro. To use, highlight cells in column A on Sheet1. the macro
will compare these same rows in Sheet2 in column B
Sub CompareSh1Sh2()
Const FirstSheet = "Sheet1"
Const SecondSheet = "Sheet2"
Const FirstSheetCol = 1
Const SecondSheetCol = 2
Worksheets(FirstSheet).Activate
Lastrow = ActiveCell.End(xlDown).Row
Set MyRange = Range(Cells(ActiveCell.Row, FirstSheetCol), _
Cells(Lastrow, FirstSheetCol))
For Each Cell In MyRange
SecondCell = Worksheets(SecondSheet). _
Cells(Cell.Row, SecondSheetCol)
If (Cell = SecondCell) Then
Cell.Interior.ColorIndex = 4
Else
Cell.Interior.ColorIndex = xlNone
End If
Next Cell
End Sub
"sharmashanu" wrote:
Hii all
I am trying to write a macro to compare first 50 values of, say column
A of sheet 1 and column B of sheet 2. I want the macro to highlight
only those cells of column A that equal to sheet 2 column B values.
thanks
|