Sub CopyRowsForNames2()
Dim Rng As Range
Dim i As Long, j As Long, Z As Long
Dim PersonName
Dim Header_
Application.ScreenUpdating = False
PersonName = Array("David", "Mary") 'you can add new names
Header_ = Array("Name", "Date", "Amount of sale", "Comission") 'Add new names for header if you want
Set Rng = ThisWorkbook.Sheets("MasterPayroll").UsedRange 'Change name of the master sheet from ""MasterPayroll"" if you want
For j = 0 To UBound(PersonName)
Application.DisplayAlerts = False
With Sheets(PersonName(j))
.Cells.Clear
.Cells(1, 1).Resize(, 4) = Header_
End With
Application.DisplayAlerts = True
Next j
For i = 2 To Rng.Rows.Count
For j = 0 To UBound(PersonName)
If Rng.Cells(i, 1) = PersonName(j) Then
Z = Sheets(PersonName(j)).UsedRange.Rows.Count
Sheets(PersonName(j)).Range(Cells(Z + 1, 1).Address, Cells(Z + 1, 4).Address) = _
Rng.Range(Cells(i, 1).Address, Cells(i, 4).Address).Value
End If
Next j
Next i
Application.ScreenUpdating = True
End Sub