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

Following is my data:
A B C
1 Oranges 6
2 Oranges 5
3 Oranges 7
4 Pomegranates 19
5 Pomegranates 16

C3 should be 18, and C5 should be 35.
Next week there will more more or fewer categories with a variable number of
entities in each.

A macro to accomplish this will save me a lot of time (and errors ??).
--
€śDoubt is uncomfortable, certainty is ridiculous.€ť (Voltaire)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 464
Default Subtotals for a variable number of rows

Subtotal feature or pivottable based of dynamic named range;
http://www.ozgrid.com/Excel/subtotal.htm
http://www.ozgrid.com/Excel/excel-pivot-tables.htm
http://www.ozgrid.com/Excel/DynamicRanges.htm


--
Regards
Dave Hawley
www.ozgrid.com
"bud i" wrote in message
...
Following is my data:
A B C
1 Oranges 6
2 Oranges 5
3 Oranges 7
4 Pomegranates 19
5 Pomegranates 16

C3 should be 18, and C5 should be 35.
Next week there will more more or fewer categories with a variable number
of
entities in each.

A macro to accomplish this will save me a lot of time (and errors ??).
--
€śDoubt is uncomfortable, certainty is ridiculous.€ť (Voltaire)


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Subtotals for a variable number of rows

Give this macro a try...

Sub SubTotals()
Dim X As Long, LastRow As Long, LastSubTotal As Long, Fruit As String
Const StartRow As Long = 1
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Fruit = Cells(StartRow, "A").Value
LastSubTotal = StartRow
For X = StartRow + 1 To LastRow + 1
If Cells(X, "A").Value < Fruit Then
Cells(X - 1, "C").Value = WorksheetFunction.Sum(Range(Cells( _
LastSubTotal, "B"), Cells(X - 1, "B")))
Fruit = Cells(X, "A").Value
LastSubTotal = X
End If
Next
End Sub

--
Rick (MVP - Excel)



"bud i" wrote in message
...
Following is my data:
A B C
1 Oranges 6
2 Oranges 5
3 Oranges 7
4 Pomegranates 19
5 Pomegranates 16

C3 should be 18, and C5 should be 35.
Next week there will more more or fewer categories with a variable number
of
entities in each.

A macro to accomplish this will save me a lot of time (and errors ??).
--
€śDoubt is uncomfortable, certainty is ridiculous.€ť (Voltaire)


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Subtotals for a variable number of rows

Hi Bud,

Is it really necessary to have the formula in column C adjacent to the last
record of the particular type? If not, you could set up a little table either
on the same worksheet on on another worksheet like the following with a list
of unique values of your column A.

Col E Col F
Item Total
Oranges 18
Pomegranates 35

You can then use SUMIF. See Help for more info on this.

Your formula in F2 in the above would be
=SUMIF(A:A,E2,B:B)

You only need to copy the formula down and you can add or delete items as
required.

If you decide to have your table in another worksheet then the formula would
be like the following. (Assuming the table is in columns E and F)

=SUMIF(Sheet1!A:A,E2,Sheet1!B:B)

--
Regards,

OssieMac


"bud i" wrote:

Following is my data:
A B C
1 Oranges 6
2 Oranges 5
3 Oranges 7
4 Pomegranates 19
5 Pomegranates 16

C3 should be 18, and C5 should be 35.
Next week there will more more or fewer categories with a variable number of
entities in each.

A macro to accomplish this will save me a lot of time (and errors ??).
--
€śDoubt is uncomfortable, certainty is ridiculous.€ť (Voltaire)

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
variable number of rows. krigger228 Excel Programming 3 February 28th 09 03:50 PM
Column Subtotals with variable number of items brentm Excel Programming 2 January 2nd 09 07:57 PM
Linking to a Variable Number of Rows - XP/07 RFJ Excel Worksheet Functions 4 May 17th 07 07:53 PM
Same operations on a variable number of rows Matt Silberstein Excel Programming 5 April 6th 05 04:40 PM
deleting variable number of rows Nick Excel Programming 1 October 29th 03 04:31 PM


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