Option Explicit
Dim LR As Long
Sub test()
Dim x, i As Long, f As Range
Dim r As Range, cel As Range, c As Range, filt As Range
'For test purpose @@@@@@@@@@@@@@@@@@@@
Range("data").Copy Cells(1, 1)
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Application.ScreenUpdating = False
Set r = Range("H:H").SpecialCells(xlCellTypeConstants)
For Each cel In r
x = TextArray(cel.Offset(, -1).Formula)
Range("D:D").AutoFilter 1, "=" & Format(cel, "#,##0.00")
Set filt = Range("C:C").SpecialCells(xlCellTypeVisible)
Range("D:D").AutoFilter
For i = 0 To UBound(x)
Set f = filt.Find(x(i))
If Not f Is Nothing Then
f.Offset(, -2).Resize(, 4).Cut cel.Offset(, 2)
Exit For
End If
Next i
Next cel
Reassemble
'Recheck for duplicate names
Set r = Range("H:H").SpecialCells(xlCellTypeConstants)
For Each cel In r
x = TextArray(cel.Offset(, -1).Formula)
Range("D" & LR & ":D" & Rows.Count).AutoFilter 1, "=" & Format(cel, "#,##0.00")
Set filt = Range("C" & LR & ":C" & Rows.Count).SpecialCells(xlCellTypeVisible)
Range("C" & LR & ":C" & Rows.Count).AutoFilter
For i = 0 To UBound(x)
Set f = filt.Find(x(i))
If Not f Is Nothing Then
cel.EntireRow.Insert
f.Offset(, -2).Resize(, 4).Cut Cells(cel.Row - 1, 1)
LR = Cells(Rows.Count, "G").End(xlUp).Row
Exit For
End If
Next i
Next cel
Application.ScreenUpdating = True
End Sub
Sub Reassemble()
LR = Cells(Rows.Count, "G").End(xlUp).Row
Range("A:A").AutoFilter Field:=1, Criteria1:="<>"
Range("A1:D" & LR).Copy Cells(LR + 2, 1)
Range("A:A").AutoFilter
Range("J1:M" & LR).Cut Cells(1, 1)
End Sub
Function TextArray(Data As String)
Dim i As Long, j As Long, m As Long, y As Long, z As Long
Dim arr()
Dim Limit
ReDim arr(10000)
Limit = 6
i = Len(Data)
y = i - 1
For m = i To Limit Step -1
For j = 1 To i - y
arr(z) = Mid(Data, j, m)
z = z + 1
Next j
y = y - 1
Next m
ReDim Preserve arr(z - 1)
TextArray = arr
End Function