Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default finding a subtotal

How would I use VBA to find a subtotal in a report.
Subtotals are based on the number of customers that we have and the subtotal
row position changes each time the report is run.

---- i do NOT want to use a pivot table ! ----
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default finding a subtotal

No pivot tables. You take all of the fun out of it...

Here is some code for finding subtotals. It looks in column B, but you can
change that pretty easily. It looks at the active sheet, but you can change
that pretty easily. It also selects the entire row where the subtotal was
found, but that can be changed pretty easily...

Public Sub FindSubTotals()
Dim wksCurrent As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Dim strFirstAddress As String
Dim rngSubTotal As Range

Set wksCurrent = ActiveSheet
Set rngToSearch = wksCurrent.Range("B1").EntireColumn
Set rngFound = rngToSearch.Find("=SUBTOTAL", , xlFormulas, xlPart, , ,
True)

If Not rngFound Is Nothing Then
strFirstAddress = rngFound.Address
Set rngSubTotal = rngFound.EntireRow
Do
Set rngFound = rngToSearch.FindNext(rngFound)
Set rngSubTotal = Union(rngSubTotal, rngFound.EntireRow)
Loop Until rngFound.Address = strFirstAddress
rngSubTotal.Select
End If

End Sub

HTH

"SharonInGa" wrote:

How would I use VBA to find a subtotal in a report.
Subtotals are based on the number of customers that we have and the subtotal
row position changes each time the report is run.

---- i do NOT want to use a pivot table ! ----

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
Subtotal To Include Item Description On Subtotal Line Tickfarmer Excel Discussion (Misc queries) 2 February 23rd 10 07:56 PM
pasting to subtotal lines without replacing hidden -non-subtotal l harleydiva67 Excel Discussion (Misc queries) 1 October 12th 06 06:02 PM
Bolding the subtotal lines automaticlly When using the Subtotal fu 06Speed6 New Users to Excel 2 October 5th 06 03:52 PM
Subtotal of Subtotal displays Grand Total in wrong row Thomas Born Excel Worksheet Functions 5 January 6th 05 01:46 PM
Sort, Subtotal, Label Subtotal, Insert row Teak Excel Programming 2 April 8th 04 04:14 PM


All times are GMT +1. The time now is 01:13 AM.

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

About Us

"It's about Microsoft Excel"