ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help! Range("startsum").Value = Application.Sum(Selection) (https://www.excelbanter.com/excel-programming/331040-help-range-startsum-value-%3D-application-sum-selection.html)

poppy

Help! Range("startsum").Value = Application.Sum(Selection)
 

Hi Everyone

I really need help with this one, I've been looking for a solutio
here, but am not getting anywhere.

I have a sheet that is populated with data from another sheet. The dat
is categorized into sectors in the target sheet. The program then need
to give a subtotal of all the records in the range. The table in th
sheet looks like this:

Code
-------------------

3. Frequency: Suburbs
Suburb Street Total
Sector 1
Basia Scukum 1
Wellington Sk 1
subtotal
Sector 2
Davie Kannerie 1
Kuyler Lamini 2
subtotal
Sector 3
Overaim Fouche 1
subtotal

-------------------


The code I have in VBA is as follows and for some reason gives me th
wrong value in the third sector:

Code
-------------------

Sheet11.Activate
Range("A14").Select
Do While ActiveCell.Value < "Total"
If ActiveCell.Value < "" Then
ActiveCell.Offset(1, 0).Activate
Else
ActiveCell.Offset(0, 2).Select
ActiveCell.Font.Bold = True

ActiveWorkbook.Names.Add Name:="startsum", RefersTo:=ActiveCell

Range(ActiveCell, ActiveCell.Offset(-1, 0).End(xlUp)).Select ' I'm thinking that my problem is here with the selection of the cells to total.
Range("startsum").Value = Application.Sum(Selection)
Range("startsum").Select
ActiveCell.Offset(0, -2).Select
ActiveCell.Offset(1, 0).Activate

End If
Loo
-------------------

--
popp
-----------------------------------------------------------------------
poppy's Profile: http://www.excelforum.com/member.php...fo&userid=1145
View this thread: http://www.excelforum.com/showthread.php?threadid=37677



All times are GMT +1. The time now is 12:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com