Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Dear All,
i have a sheet which has a lot of entries, I want to automatic page break after every 20 entries and need a sum of that 20 entries on every page break. this sum should be brought forward on next page and including the next sum on next page break. Is it possible thru VBA. Thnx in advance |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub addbreaks()
Done = False LastTotal = 1 RowCount = 1 For Count = 1 To (RowCount + 20) RowCount = Count If IsEmpty(Cells(Count, "B")) Then Done = True Exit For End If Next Count Do Cells(RowCount, "B").EntireRow.Insert Cells(RowCount, "A") = "Subtotal" If LastTotal = 1 Then Cells(RowCount, "B").Formula = "=sum(B" & LastTotal & _ ":B" & (RowCount - 1) & ")" Else Cells(RowCount, "B").Formula = "=sum(B" & LastTotal & _ ":B" & (RowCount - 1) & ") + B" & (LastTotal - 1) End If ActiveWindow.SelectedSheets.HPageBreaks.Add _ Befo=Cells(RowCount + 1, "B") LastTotal = RowCount + 1 'get next row For Count = LastTotal To (LastTotal + 20) If IsEmpty(Cells(Count, "B")) Then Done = True Exit For End If Next Count RowCount = Count Loop While Done = False If RowCount < LastRow Then Cells(RowCount, "B").EntireRow.Insert Cells(RowCount, "A") = "Subtotal" If LastTotal = 1 Then Cells(RowCount, "B").Formula = "=sum(B" & LastTotal & _ ":B" & (RowCount - 1) & ")" Else Cells(RowCount, "B").Formula = "=sum(B" & LastTotal & _ ":B" & (RowCount - 1) & ") + B" & (LastTotal - 1) End If ActiveWindow.SelectedSheets.HPageBreaks.Add _ Befo=Cells(RowCount + 1, "B") End If End Sub "shaqil" wrote: Dear All, i have a sheet which has a lot of entries, I want to automatic page break after every 20 entries and need a sum of that 20 entries on every page break. this sum should be brought forward on next page and including the next sum on next page break. Is it possible thru VBA. Thnx in advance |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel 2007 Page Break Adjustments causes a page break each cell | Excel Worksheet Functions | |||
Subtotal-new spreadsheet at each break? | Excel Worksheet Functions | |||
How do I do page breaks when view menu doesnt page break preview | Excel Discussion (Misc queries) | |||
Subtotal page break error? | Excel Worksheet Functions | |||
adding a new page break to an existing page break | Excel Discussion (Misc queries) |