Give this a try
Option Explicit
Sub abc()
Dim ptr As Long, i As Long, ii As Long, n As Long
Dim a As Variant, b()
With Worksheets("Sheet2")
a = .Range("a3:f" & .Cells(Rows.CountLarge, "a").End(xlUp).Row)
.Range("a1:f2").Copy Worksheets("Sheet1").Range("k1")
End With
With Worksheets("Sheet1")
ReDim b(1 To .Cells(Rows.CountLarge, "a").End(xlUp).Row, 1 To 6)
For ptr = 3 To .Cells(Rows.CountLarge, "a").End(xlUp).Row
For i = 1 To UBound(a)
If CStr(.Cells(ptr, "h")) = CStr(a(i, 5)) And Left(CStr(.Cells(ptr, "i")), 6) = Left(CStr(a(i, 6)), 6) And Right(CStr(.Cells(ptr, "i")), 4) = Right(CStr(a(i, 6)), 4) Then
For ii = 1 To UBound(a, 2)
Select Case ii
Case Is = 5, 6
b(ptr - 2, ii) = "'" & a(i, ii)
Case Else
b(ptr - 2, ii) = a(i, ii)
End Select
Next
Exit For
End If
Next
Next
.Cells(3, "k").Resize(UBound(b), 6) = b
End With
End Sub
Bookmarks