Try
Sub test()
Dim a, b, i As Long, ii As Long, txt As String, w, x
b = Application.Trim(Sheets("CUSTOMER DATA").Cells(1).CurrentRegion.Value)
a = Application.Trim(Sheets("MAIN DATA").[a3].CurrentRegion.Value)
With CreateObject("Scripting.Dictionary")
For i = 2 To UBound(a, 1)
If a(i, 1) = "" Then a(i, 1) = a(i - 1, 1)
If a(i, 2) <> "" Then
txt = Join(Array(a(i, 1), a(i, 2), a(i, 3)), Chr(2))
If Not .exists(txt) Then
ReDim w(1 To 8)
For ii = 1 To UBound(a, 2)
w(ii + IIf(ii > 1, 1, 0)) = a(i, ii)
Next
x = Application.Match(a(i, 1) & "*", Application.Index(b, 0, 3), 0)
If IsNumeric(x) Then w(2) = b(x, 4)
.Item(txt) = w
End If
End If
Next
a = Application.Index(.items, 0, 0)
End With
With Sheets.Add
Sheets("main data").Rows(3).Copy .[a3]
.[b3].Insert xlShiftToRight
.[b3].Value = "Company ID"
.[a4].Resize(UBound(a, 1), UBound(a, 2)) = a
.[a3].CurrentRegion.Borders.Weight = 2
.Columns.AutoFit
End With
End Sub
Bookmarks