Concatenate values from two different column and use that as range in match function without saving values in any other column
I need to highlight values which are duplicate in two column values.
Untitled picture.png
I have below code which is working only for B column but not combining C column.
Public Sub Validate1()
CheckMaterialNumber "Sheet1", "B", "C", 3
End Sub
Public Sub CheckMaterialNumber(DestinationSheet As String, MaterialNumCol As
String, PlantCol As String, startrow As Long)
Dim EndRow As Long
Dim row As Long
EndRow = Worksheets(DestinationSheet).Range("B" & Rows.Count).End(xlUp).row
For row = startrow To EndRow
Dim EMaterilNumber As String
EMaterilNumber = Worksheets(DestinationSheet).Range(MaterialNumCol & CStr(row)).Value
Dim Tmatch As Long
On Error Resume Next
Tmatch = application.WorksheetFunction.CountIf(Worksheets(DestinationSheet).Range("B2:B" & EndRow), EMaterilNumber)
If Tmatch > 1 Then
Worksheets(DestinationSheet).Range(MaterialNumCol + CStr(row)).Interior.ColorIndex = 3
Else
Worksheets(DestinationSheet).Range(MaterialNumCol + CStr(row)).Interior.ColorIndex = 43
End If
Next row
End Sub
Bookmarks