![]() |
subtotal on page break
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 |
subtotal on page break
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 |
All times are GMT +1. The time now is 12:34 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com