Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Print Subtotals of variable entries

The procedure below was used to print out blocks of data on individual
sheets based on the entries in Column B. It has been changed but for the
purposes of my query it is perhaps simpler to use this one. In column P
there are number entries. The number of rows printed will vary depending
on the entries in Column B. eg if B5,B6 and B7 have the same value then
the printout will be of three rows plus the headers. What I would like
is to have this printout but with the total of the figures in column P.
So if B5, B6 and B7 were Field 1 and C5,C6 and C7 were 1,2 and 3 the
printout would show these figures with the subtotal 6 below the
individual entries. I know a pivot table will create this but I thought
this would dramatically complicate something that already prints out
fine. I value as always any guidance.

Dim cell As Range
Dim lCount As Long
Dim rCol As Range
'Get the last cell in column B
With Sheets("Field Records")
Set rCol = .Range("B10", .Range("B" & .Rows.Count).End(xlUp))
End With
'Loop through column B
For Each cell In rCol.Cells
'If a new value
If cell.Value < cell.Offset(-1, 0).Value Then
'Count the number of similar values in col B
lCount = Application.CountIf(rCol, cell.Value)
'Resize a range and print it out
cell.Resize(lCount, 17).PrintOut
End If
Next cell

Kind regards
Graham Haughs
Turriff, Scotland
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Print Subtotals of variable entries

Dim cell As Range
Dim lCount As Long
Dim rCol As Range
Dim sh as Worksheet, sh1 as Worksheet
Dim rng as Range
set sh = Sheets("Field Records")
worksheets.Add After:=Worksheets(worksheets.count)
set sh1 = Activesheet
sh.Activate
'Get the last cell in column B
With sh
Set rCol = .Range("B10", .Range("B" & .Rows.Count).End(xlUp))
End With
'Loop through column B
For Each cell In rCol.Cells
'If a new value
If cell.Value < cell.Offset(-1, 0).Value Then
'Count the number of similar values in col B
lCount = Application.CountIf(rCol, cell.Value)
'Resize a range and print it out
sh1.Cells.Clear
cell.Resize(lCount, 17).EntireRow.copy sh1.Range("A1")
set rng = sh1.Cells(lcount + 1,"P")
rng.FormulaR1C1 = "=Sum(R1C:R[-1]C)"
sh1.cells(lcount+1,1).Resize(,17).printout
End If
Next cell
Application.DisplayAlerts = False
sh1.Delete
Application.DisplayAlerts = True

--
Regards,
Tom Ogilvy


"Graham Haughs" wrote:

The procedure below was used to print out blocks of data on individual
sheets based on the entries in Column B. It has been changed but for the
purposes of my query it is perhaps simpler to use this one. In column P
there are number entries. The number of rows printed will vary depending
on the entries in Column B. eg if B5,B6 and B7 have the same value then
the printout will be of three rows plus the headers. What I would like
is to have this printout but with the total of the figures in column P.
So if B5, B6 and B7 were Field 1 and C5,C6 and C7 were 1,2 and 3 the
printout would show these figures with the subtotal 6 below the
individual entries. I know a pivot table will create this but I thought
this would dramatically complicate something that already prints out
fine. I value as always any guidance.

Dim cell As Range
Dim lCount As Long
Dim rCol As Range
'Get the last cell in column B
With Sheets("Field Records")
Set rCol = .Range("B10", .Range("B" & .Rows.Count).End(xlUp))
End With
'Loop through column B
For Each cell In rCol.Cells
'If a new value
If cell.Value < cell.Offset(-1, 0).Value Then
'Count the number of similar values in col B
lCount = Application.CountIf(rCol, cell.Value)
'Resize a range and print it out
cell.Resize(lCount, 17).PrintOut
End If
Next cell

Kind regards
Graham Haughs
Turriff, Scotland

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Print Subtotals of variable entries

Tom, you are, as always, staggeringly amazing.
Many thanks.

Graham

Tom Ogilvy wrote:
Dim cell As Range
Dim lCount As Long
Dim rCol As Range
Dim sh as Worksheet, sh1 as Worksheet
Dim rng as Range
set sh = Sheets("Field Records")
worksheets.Add After:=Worksheets(worksheets.count)
set sh1 = Activesheet
sh.Activate
'Get the last cell in column B
With sh
Set rCol = .Range("B10", .Range("B" & .Rows.Count).End(xlUp))
End With
'Loop through column B
For Each cell In rCol.Cells
'If a new value
If cell.Value < cell.Offset(-1, 0).Value Then
'Count the number of similar values in col B
lCount = Application.CountIf(rCol, cell.Value)
'Resize a range and print it out
sh1.Cells.Clear
cell.Resize(lCount, 17).EntireRow.copy sh1.Range("A1")
set rng = sh1.Cells(lcount + 1,"P")
rng.FormulaR1C1 = "=Sum(R1C:R[-1]C)"
sh1.cells(lcount+1,1).Resize(,17).printout
End If
Next cell
Application.DisplayAlerts = False
sh1.Delete
Application.DisplayAlerts = True

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
Subtotals with variable total/sum location Dawn Bjork Buzbee Excel Programming 2 April 7th 06 10:13 PM
Subtotals with variable total/sum location Tom Ogilvy Excel Programming 0 April 7th 06 06:30 PM
get subtotals results as a variable Przemek Wrzesiński Excel Programming 4 August 7th 05 08:42 PM
Is there a way where I can print subtotals on each pages? George Lim Setting up and Configuration of Excel 1 March 27th 05 10:26 AM
Print Area when subtotals are on. Ben Allen Excel Programming 0 April 22nd 04 09:41 PM


All times are GMT +1. The time now is 08:11 AM.

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"