Sub HighlightValuesFound()
' Worksheet containing values to "look for".
Dim wsLookFor As Worksheet
' Worksheet containing values to "look at".
Dim wsLookAt As Worksheet
' Look for values that are in this range...
Dim rLookForValuesRange As Range
' ...within this range.
Dim rLookAtValuesRange As Range
' Range object for looping lookup values range.
Dim rLookForValueCell As Range
' First data cell containing values to "look for".
Dim rLookForValuesRangeAnchor As Range
' First data cell containing values to "look in".
Dim rLookAtValuesRangeAnchor As Range
' Count of how many "look for" cells to process.
Dim iCountCellsLookFor As Long
' Count of how many "look at" cells to process.
Dim iCountCellsLookAt As Long
' Flag indicating if the "look for" value is found in the "look at" range.
Dim bFound As Boolean
' Point workshet object to worksheet containing values to "look for".
Set wsLookFor = ThisWorkbook.Worksheets("Sheet2")
' Point workshet object to worksheet containing values to "look at".
Set wsLookAt = ThisWorkbook.Worksheets("Sheet1")
' First (leftmost) cell containing data to "look for".
Set rLookForValuesRangeAnchor = wsLookFor.Range("A1")
' First (topmost) cell containing data to "look at".
Set rLookAtValuesRangeAnchor = wsLookAt.Range("A1")
' Get count of values to look for.
iCountCellsLookFor = rLookForValuesRangeAnchor.Cells(1, Columns.Count).End(xlToLeft).Column
iCountCellsLookFor = iCountCellsLookFor - rLookForValuesRangeAnchor.Column
' Get count of values to look at.
iCountCellsLookAt = rLookAtValuesRangeAnchor.Cells(Rows.Count, 1).End(xlUp).Row + 1
iCountCellsLookAt = iCountCellsLookAt - rLookAtValuesRangeAnchor.Row + 1
' Range containing values to look for.
Set rLookForValuesRange = rLookForValuesRangeAnchor.Resize(1, iCountCellsLookFor)
' Range containing values to look at.
Set rLookAtValuesRange = rLookAtValuesRangeAnchor.Resize(iCountCellsLookAt, 1)
' Get rid of existing highlights in values to look for range.
With rLookForValuesRange.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
' Loop through values to find (range).
For Each rLookForValueCell In rLookForValuesRange
' If value in range to "look in" is found in range to "look at"
' then bFound = TRUE. Use function named IsValueInRange to do that.
bFound = IsValueInRange(rLookForValueCell.Value, rLookAtValuesRange)
If bFound _
Then
' If value to "look for" is in the range to "look at" then highlight it.
With rLookForValueCell.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
Next rLookForValueCell
End Sub
'
Function IsValueInRange(pvValueToLookFor As Variant, prValuesToLookAt As Range) As Boolean
Dim rCell As Range
IsValueInRange = False
For Each rCell In prValuesToLookAt
If rCell.Value = pvValueToLookFor _
Then
IsValueInRange = True
Exit For
End If
Next rCell
End Function