Sub test()
Dim a, b, x, i As Long, ii As Long, rngSite As Range
Dim myCols(), n As Long, myS, temp, t As Long
Set rngSite = Sheets("SITE_TABLE").Cells(1).CurrentRegion
With Sheets("matching").Cells(1).CurrentRegion
t = Application.Match("output field", .Rows(1), 0)
For ii = 1 To t - 1
If .Cells(1, ii).Address = .Cells(1, ii).MergeArea(1).Address Then
n = n + 1: ReDim Preserve myCols(1 To 2, 1 To n)
myCols(1, n) = ii: myCols(2, n) = .Cells(1, ii).MergeArea.Count + ii - 1
End If
Next
a = .Resize(, t - 1).Value
.Columns(t).Offset(2).Resize(, 100).ClearContents
b = .Columns(t).Resize(, 100).Value
For i = 3 To UBound(a, 1)
ReDim myS(1 To myCols(2, 2) - myCols(2, 1) + 1)
For ii = myCols(1, 2) To myCols(2, 2)
If a(i, ii) <> "" Then myS(ii) = a(i, ii)
Next
For ii = myCols(1, 3) To myCols(2, 3)
If a(i, ii) <> "" Then
x = Application.VLookup(a(i, ii), rngSite, 2, False)
ReDim Preserve myS(1 To UBound(myS) + 1)
myS(UBound(myS)) = x
End If
Next
n = 0
For ii = myCols(1, 4) To myCols(2, 4)
If a(i, ii) <> "" Then
x = Application.VLookup(a(i, ii), rngSite, 2, False)
If x <> "" Then
If IsError(Application.Match(x, myS, 0)) Then
n = n + 1: b(i, n) = a(i, ii)
End If
Else
n = n + 1: b(i, n) = a(i, ii) & " (No Match)"
End If
End If
Next
Next
.Columns(t).Resize(, UBound(b, 2)).Value = b
End With
End Sub
Bookmarks