Sub LinkSort()
Dim lRow As Long, match As Long, noIDs As Long, iD As Long, idPos As Long, cRow As Long, endLoop As Long
Dim multIDs As Long
Dim str As String, replaced As String, LnkID As String
Dim rng As Range
lRow = Cells(Rows.Count, 1).End(xlUp).Row
Set rng = Range(Cells(1, 1), Cells(lRow, 1))
endLoop = rng.Rows.Count
cRow = 2
multIDs = 0
While cRow <= endLoop
str = Cells(cRow, "N").Value
replaced = Replace(str, "-", "")
noIDs = Len(str) - Len(replaced)
Select Case noIDs
Case Is = 1
On Error Resume Next
match = Application.match(Cells(cRow, "N").Value, rng, 0) + 1
If match <> 0 And cRow <> match Then
On Error GoTo 0
Rows(cRow & ":" & cRow).Cut
Rows(match & ":" & match).Insert Shift:=xlDown
If match > rng.Rows.Count Then
Set rng = Range(Cells(1, 1), Cells(Cells(Rows.Count, 1).End(xlUp).Row, 1))
End If
match = 0
Else
cRow = cRow + 1
match = 0
End If
Case Is > 1
multIDs = multIDs + 1
Rows(cRow & ":" & cRow).Cut
Rows(Cells(Rows.Count, 1).End(xlUp).Row + 1 & ":" & Cells(Rows.Count, 1).End(xlUp).Row + 1).Insert Shift:=xlDown
Set rng = Range(Cells(1, 1), Cells(Cells(Rows.Count, 1).End(xlUp).Row, 1))
endLoop = endLoop - 1
match = 0
Case Is = 0
cRow = cRow + 1
match = 0
End Select
On Error GoTo 0
Wend
If multIDs <> 0 Then
cRow = endLoop + 1
endLoop = endLoop + multIDs
For cRow = cRow To endLoop
str = Cells(cRow, "N").Value
replaced = Replace(str, "-", "")
noIDs = Len(str) - Len(replaced)
Rows(cRow & ":" & cRow).Copy
Rows(cRow + 1 & ":" & cRow + noIDs - 1).Insert Shift:=xlDown
Application.CutCopyMode = False
Set rng = Range(Cells(1, 1), Cells(Cells(Rows.Count, 1).End(xlUp).Row, 1))
endLoop = endLoop + noIDs - 1
LnkID = Cells(cRow, "N").Value
idPos = 0
For iD = 1 To noIDs
idPos = InStr(idPos + 1, LnkID, "-", vbTextCompare)
If idPos <> 0 Then
On Error Resume Next
match = Application.match(Mid(LnkID, idPos - 4, 6), rng, 0)
If match <> 0 And cRow <> match + 1 Then
On Error GoTo 0
Rows(cRow & ":" & cRow).Cut
Rows(match + 1 & ":" & match + 1).Insert Shift:=xlDown
If cRow > match + 1 Then cRow = cRow + 1
End If
End If
Next iD
Next cRow
End If
End Sub