Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default how to get totals?

I have a spreadsheet in the form of:
Cell Data
B1 0.5
B2 0.25
B3 empty
B4 1.0
B5 1.25
B6 0.75
B7 empty

using vb6/vba I'm trying to get totals into the empty cells (i.e. cell
B3 would contain a total for cells B1:B2; cell B7 would contain a
total for cells B4:B6).

Here's what I've got but it isn't working:
ActiveCell.Formula = "=SUM(" & cellRef & ":" & theDiff & ")"

the variable cellRef represents the previous empty cell and the
variable theDiff represents the current empty cell -1.
So in the example above, cellRef might represent cell B3 and theDiff
might represent cell B6.

I'm getting totals but it seems to be a running total rather than a
subtotal. In other words the first subtotal is correct but then the
next subtotal is a total of all the cells above it, not just the cells
since the last subtotal. So in the example above, what I'm currently
getting for the first subtotal is 0.75, which is correct. What I'm
currently getting for the second subtotal is 3.75, which is incorrect;
it should be 3.0.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,124
Default how to get totals?

Try this idea

Sub sumaboveblank()
mc = "f"
lr = Cells(Rows.Count, mc).End(xlUp).Row
'MsgBox lr
For i = lr To 2 Step -1
If Cells(i, mc) = "" Then
br = i
'MsgBox br
nextup = Cells(br - 1, mc).End(xlUp).Row
'MsgBox nextup
Cells(br, mc) = Application.Sum(Range(Cells(nextup, mc), Cells(br, mc)))
End If
Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"spowel4" wrote in message
...
I have a spreadsheet in the form of:
Cell Data
B1 0.5
B2 0.25
B3 empty
B4 1.0
B5 1.25
B6 0.75
B7 empty

using vb6/vba I'm trying to get totals into the empty cells (i.e. cell
B3 would contain a total for cells B1:B2; cell B7 would contain a
total for cells B4:B6).

Here's what I've got but it isn't working:
ActiveCell.Formula = "=SUM(" & cellRef & ":" & theDiff & ")"

the variable cellRef represents the previous empty cell and the
variable theDiff represents the current empty cell -1.
So in the example above, cellRef might represent cell B3 and theDiff
might represent cell B6.

I'm getting totals but it seems to be a running total rather than a
subtotal. In other words the first subtotal is correct but then the
next subtotal is a total of all the cells above it, not just the cells
since the last subtotal. So in the example above, what I'm currently
getting for the first subtotal is 0.75, which is correct. What I'm
currently getting for the second subtotal is 3.75, which is incorrect;
it should be 3.0.


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
Pivot Totals: Group totals different from Grand totals PsyberFox Excel Discussion (Misc queries) 1 February 13th 08 06:16 PM
Grand Totals with Nested Sub Totals Brenda from Michigan Excel Discussion (Misc queries) 7 January 18th 08 01:26 PM
how to enter totals and sub totals from receipts into excel. mjd23 New Users to Excel 2 January 11th 08 01:54 AM
Summing Weekly Totals into Monthly Totals steph44haf Excel Worksheet Functions 3 July 5th 06 04:51 PM
Comparing/matching totals in a column to totals in a row Nicole L. Excel Worksheet Functions 3 January 27th 05 10:42 PM


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

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"