See if this is close to what you are looking for
Still using sheet2 - so have not deleted
Run macro with CTRL + t
Sub IndividualStatements()
Dim ws As Worksheet, wt As Worksheet
Dim lR As Long
Dim myStr As String
Dim cellRowA As Long, cellRowB As Long
Set ws = Sheets("Sheet1")
Set wt = Sheets("Sheet2")
lR = ws.Range("A1048576").End(xlUp).Row
With wt
.Cells.Clear 'clear prior values
'create table of ranges to copy from sheet1 including first& last rows
s = 1
For r = 1 To lR
If ws.Cells(r, 1).Value = "AGENT STATEMENT" Then
s = s + 1
.Cells(s, 2) = r - 1
.Cells(s - 1, 3) = r - 2
If s = 2 Then .Cells(s - 1, 3) = ""
End If
If ws.Cells(r, 1).Value = "To:" Then
ws.Cells(r, 2).Copy Destination:=.Cells(s, 1)
End If
If r = lR Then .Cells(s, 3) = r
Next r
lR = .Range("A1048576").End(xlUp).Row
For s = lR To 2 Step -1
If .Cells(s, 1) = .Cells(s - 1, 1) Then
.Cells(s - 1, 3) = .Cells(s, 3)
.Rows(s).EntireRow.Delete
End If
Next s
.Cells(1, 2).Value = "From row"
.Cells(1, 3).Value = "To row"
lR = .Range("A1048576").End(xlUp).Row
For s = 2 To lR
cellRowA = .Cells(s, 2).Value
cellRowB = .Cells(s, 3).Value
'create worksheets for each customer
On Error Resume Next
Application.DisplayAlerts = False
Sheets(.Cells(s, 1).Value).Delete
Sheets("sheet3").Delete
Application.DisplayAlerts = True
Worksheets.Add.Name = .Cells(s, 1).Value
Cells.Clear
Set myrange = ws.Range("A" & cellRowA & ":G" & cellRowB)
myrange.Copy
Cells(1, 1).PasteSpecial
Next s
End With
End Sub
Bookmarks