Sub split_REB()
Dim wsName As String
Dim startRow As Integer
lastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A1:N" & lastRow)
.Header = xlYes
.Orientation = xlTopToBottom
.Apply
End With
For i = 1 To lastRow
If Cells(i, 5) <> Cells(i + 1, 5) And Not IsEmpty(Cells(i + 1, 5)) Then
wsName = Cells(i + 1, 5)
startRow = i + 1
Range("A1:N1").Copy
Sheets.Add
ActiveSheet.Name = wsName
ActiveSheet.Paste
Range("A2").Select
Sheets("Sheet1").Select
End If
If Cells(i + 1, 5) <> Cells(i + 2, 5) Then
Range("A" & startRow & ":N" & i + 1).Select
Selection.Copy
Sheets(wsName).Select
ActiveSheet.Paste
Sheets("Sheet1").Select
End If
Next i
End Sub
Call this when you split data to new workbook
Bookmarks