I've changed the code to add a new line (in bold) which specifies the source sheet:
Sub MultiMatch()
Const lDATA_COL As Long = 1
Const lSTART_ROW As Long = 2
Const sSEARCH_SHEET As String = "Sheet1"
Const sSOURCE_SHEET As String = "Sheet1"
Const lOUTPUT_OFFSET As Long = 1
Dim avRanges As Variant
Dim avDescription As Variant
Dim lLastRow As Long
Dim rngLoop As Range
Dim bMatched As Boolean
Dim lSearchLoop As Long
Dim vSearchResult As Variant
avRanges = Array("F:F", "H:H", "J:J")
avDescription = Array("Priority 1", "Priority 2", "Priority 3")
With Sheets(sSOURCE_SHEET)
lLastRow = Cells(Rows.Count, lDATA_COL).End(xlUp).Row
For Each rngLoop In .Range(.Cells(lSTART_ROW, lDATA_COL), .Cells(lLastRow, lDATA_COL)).Cells
If Not rngLoop.Value = "" Then
bMatched = False
lSearchLoop = LBound(avRanges)
While Not bMatched And lSearchLoop <= UBound(avRanges)
vSearchResult = Application.Match(rngLoop.Value, Sheets(sSEARCH_SHEET).Range(avRanges(lSearchLoop)), 0)
If Not IsError(vSearchResult) Then
bMatched = True
Else
lSearchLoop = lSearchLoop + 1
End If
Wend
If bMatched Then
rngLoop.Offset(0, lOUTPUT_OFFSET).Value = avDescription(lSearchLoop)
End If
End If
Next rngLoop
End With
End Sub
The first proper line of code specifies the column that the data being searched for is in, so:
Const lDATA_COL As Long = 1
1 = Column A, if you wanted your source data to be in column C you'd change that line to:
Const lDATA_COL As Long = 3
The code also automatically finds the last row in the data column containing data and loop down to there, so it will work with any number of entries in the specified data column.
Bookmarks