Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default range problem with multiple use of subtotal function

Even if you create the second set of subtotals manually, you get a
second grand total row. I don't think you can avoid the duplicates when
you create the subtotals programmatically.

wrote:
Hi, I'm hoping someone can help me. I'm working with Excel97.
Using the subtotal function, is there a way to find the number of rows
that now exist after the subtotal has done its' magic?
Problems/reasons below...

I'm seeking to automate creating subtotals on a spreadsheet. Here is a
snippet of the code I'm working with:

' Clear all subtotals
Cells.Select
Selection.RemoveSubtotal
' Select range of data
Range("labor_test").Select
' Do first subtotal
Selection.Subtotal GroupBy:=1, Function:=xlSum,
TotalList:=Array(8, 9), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
'(THIS IS WHERE I HAVE THE PROBLEM)
' Do the next subtotal
Selection.Subtotal GroupBy:=2, Function:=xlSum,
TotalList:=Array(8, 9), _
Replace:=False, PageBreaks:=False, SummaryBelowData:=True

My problem is that doing this via VBA, it seems to not be able to
figure out what the range is supposed to be for the second subtotal -
it seems to think the range is short by the number of subtotal rows
and it misbehaves and creates extra subtotal lines. When I use the
pulldown on the toolbar under Data, Subtotals, it keeps track of the
selection range and has the right number of rows highlighted when I go
to repeat the proceedure. I did use the macro recorder, but what you
see above is exactly what it gave me.
Thanks!!!



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default range problem with multiple use of subtotal function

Thanks for the reply. I don't mind seeing multiple grand total liine,
what I minded was the fact that when the second subtotal executed, it
only used part of the data and left 15% of the data hanging out on the
other side of the second subtotal, thus creating garbage data.
However, I was able to fix my problem by looking at other people's
questions/answers dealing with subtotals and finding a way to reset
the range.

Here's what I ended up doing:

ActiveWorkbook.Worksheets("WORKSHEET_A").Activate
Set awks = ActiveSheet
' Which columns do I want subtotals for?
intcol(1) = 1
intcol(2) = 2
intcol(3) = 4
intcol(4) = 6

With awks
Cells.Select
Selection.RemoveSubtotal
For i = 1 To 4
' Find the bottom non empty cell to reset the range to the whole
selectionn
lastrow = .Cells(.Rows.Count, "A").End(xlUp).row
Set rng = .Range("a1:j" & lastrow)
rng.Select
' If first time through, have replace be true (probably redundant)
If i = 1 Then
breplace = True
Else
breplace = False
End If
' Do subtotal on group/column
Selection.Subtotal GroupBy:=intcol(i), Function:=xlSum, _
TotalList:=Array(8, 9), Replace:=breplace, _
PageBreaks:=False, SummaryBelowData:=True
Next
' Roll everything up
.Outline.ShowLevels RowLevels:=5
.Outline.ShowLevels RowLevels:=4
.Outline.ShowLevels RowLevels:=3
.Outline.ShowLevels RowLevels:=2
End With

Debra Dalgleish wrote in message ...
Even if you create the second set of subtotals manually, you get a
second grand total row. I don't think you can avoid the duplicates when
you create the subtotals programmatically.

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
Problem with subtotal function Constance Excel Worksheet Functions 0 March 17th 10 05:57 PM
Display Multiple Cells when Using Subtotal Function Tickfarmer Excel Discussion (Misc queries) 0 August 26th 09 02:50 PM
function problem regarding cell range chindo Excel Worksheet Functions 1 November 10th 05 03:06 AM
INTRICATE PROBLEM- How to find multiple text,excluding "H", in a multiple range of cells, then replacing 0 with another number in another cell Tourcat Excel Worksheet Functions 1 February 8th 05 06:26 PM
Passing a Range to a Function Problem Rocky McKinley Excel Programming 4 January 7th 04 02:00 AM


All times are GMT +1. The time now is 05:33 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"