Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 Page Break Adjustments causes a page break each cell BKaufman Excel Worksheet Functions 2 September 10th 10 05:02 AM
Subtotal-new spreadsheet at each break? DRayner Excel Worksheet Functions 1 February 8th 08 12:35 AM
How do I do page breaks when view menu doesnt page break preview HeatherF55 Excel Discussion (Misc queries) 0 September 21st 07 04:24 AM
Subtotal page break error? Dips Excel Worksheet Functions 0 May 9th 06 11:21 PM
adding a new page break to an existing page break Edward Letendre Excel Discussion (Misc queries) 1 March 6th 05 09:29 AM


All times are GMT +1. The time now is 11:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"