Hi again Gary,
The following macro will set the interior color of the cells in column A to
yellow if they are found in column B. It then inserts the address of the
column A value in column C adjacent to the found value (there could be
multiple occurrences of this address).
Sub Match_Values()
Dim rngA As Range
Dim rngB As Range
Dim CellA As Range
Dim foundCell As Range
Dim firstAddress As String
'Following assigns ranges of unknown length to
'variables starting from first cell of range.
With Sheets("Sheet1")
Set rngA = Range(.Cells(1, 1), _
.Cells(Rows.Count, 1).End(xlUp))
Set rngB = Range(.Cells(1, 2), _
.Cells(Rows.Count, 2).End(xlUp))
End With
'Alternative method of assigning ranges to a
'variable where the range is fixed and known.
'Set rngA = Sheets("Sheet1").Range("A1:A200")
'Set rngB = Sheets("Sheet1").Range("B1:B1500")
For Each CellA In rngA
With rngB
Set foundCell = .Find(What:=CellA, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If Not foundCell Is Nothing Then
firstAddress = foundCell.Address
Do
'Set interior color of found cell to yellow
CellA.Interior.ColorIndex = 6
'Insert cell address from column A
foundCell.Offset(0, 1) = CellA.Address
Set foundCell = .FindNext(foundCell)
Loop While Not foundCell Is Nothing And _
foundCell.Address <> firstAddress
End If
End With
Next CellA
End Sub
Regards,
OssieMac