Sub CopyRows2()
Dim c As Range, rBlanks As Range
Dim nRows As Long
Dim sWsName As String
Dim vWords As Variant
With ActiveSheet
nRows = .Cells(.Rows.Count, "D").End(xlUp).Row - 1
If nRows < 1 Then Exit Sub
Application.ScreenUpdating = False
For Each c In .Range("D2").Resize(nRows)
vWords = Split(c, " ")
If UBound(vWords) Then
sWsName = vWords(0) & " " & vWords(1)
Else
sWsName = c
End If
If SheetExists(sWsName) Then
c.EntireRow.Copy Sheets(sWsName) _
.Cells(Rows.Count, "A").End(xlUp).Offset(1)
c.ClearContents '--mark row for deletion
Else
MsgBox c.Address & ": Sheet """ & _
sWsName & """ not found"
End If
Next c
Set rBlanks = .Range("D2").Resize(nRows) _
.SpecialCells(xlCellTypeBlanks)
If Not rBlanks Is Nothing Then _
rBlanks.EntireRow.Delete
End With
Application.ScreenUpdating = True
End Sub
Private Function SheetExists(sName As String) As Boolean
On Error Resume Next
SheetExists = Sheets(sName).Index > 0
End Function