Hi friends,
in this code i dividing one single sheet data into different sheets , based on the producer name into a sheet. now i have attached the file i need the page break to be given after every reporting period in the sheet like wise in all the sheets.
Sub sep_producer()
Dim prodname As String
Dim templrow As Long
Dim j As Long
StRow = 1
lrow = Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To lrow + 1
If Worksheets("Sheet1").Range("A" & i).Value Like "Report Period*" And i <> 1 Or i = lrow + 1 Then
prodname = Right(Worksheets("Sheet1").Range("A" & StRow + 4).Value, Len(Worksheets("Sheet1").Range("A" & StRow + 4).Value) - 10)
If Not Evaluate("ISREF('" & prodname & "'!A1)") Then
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = prodname
End If
templrow = Worksheets(prodname).Range("A" & Rows.Count).End(xlUp).Row
Worksheets("Sheet1").Range("A" & StRow & ":H" & RowCount).Copy
Worksheets(prodname).Range("A" & templrow + 2).PasteSpecial Paste:=xlValues
Worksheets(prodname).Range("A" & templrow + 2).PasteSpecial Paste:=xlFormats
Worksheets(prodname).Cells.EntireColumn.AutoFit
Worksheets(prodname).Columns("H:H").ColumnWidth = 37.14
Worksheets(prodname).Cells.EntireRow.AutoFit
StRow = i
RowCount = RowCount + 1
ElseIf Worksheets("Sheet1").Range("A" & i).Value Like "Report Period*" And i = 1 Then
RowCount = RowCount + 1
Else
RowCount = RowCount + 1
End If
Next i
For j = 1 To Worksheets.Count
With Worksheets(j)
If .Range("A1") = "" And .Range("A2") = "" Then
.Rows("1:2").Delete
End If
End With
Next j
End Sub
Bookmarks