ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Sum a Column of Variable length (https://www.excelbanter.com/excel-discussion-misc-queries/54060-sum-column-variable-length.html)

Chris G

Sum a Column of Variable length
 
Hi,

I wish to put a total AT THE BOTTOM of a list of numbers in a macro.
The list is variable length and I want to use the subtotal(109, function as
there will be filters applied to the data and I only wish it to add items
displayed.

I tried this but it crashed on the last line. Help Please!!
LastRowNumber = Range("D65536").End(xlUp).Row
Moveup = LastRowNumber - 2
ActiveCell.SpecialCells(xlLastCell).Select
ActiveCell.Offset(1, -1).Range("A1").Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(109,R[-Moveup]C:R[-1]C)"



Chris G

Sum a Column of Variable length
 
When I say "in a macro" I really mean "using a macro".
The list of numbers is in the spreadsheet and the formula is to be put in
the spreadsheet. Sorry about any potential confusion.

"Chris G" wrote:

Hi,

I wish to put a total AT THE BOTTOM of a list of numbers in a macro.
The list is variable length and I want to use the subtotal(109, function as
there will be filters applied to the data and I only wish it to add items
displayed.

I tried this but it crashed on the last line. Help Please!!
LastRowNumber = Range("D65536").End(xlUp).Row
Moveup = LastRowNumber - 2
ActiveCell.SpecialCells(xlLastCell).Select
ActiveCell.Offset(1, -1).Range("A1").Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(109,R[-Moveup]C:R[-1]C)"



Bob Phillips

Sum a Column of Variable length
 
Try

LastRowNumber = Range("D" & Rows.Count).End(xlUp).Row
MoveUp = LastRowNumber - 2
Cells(LastRowNumber + 1, "D").FormulaR1C1 = "=SUBTOTAL(9,R[-" & MoveUp &
"]C:R[-1]C)"


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Chris G" wrote in message
...
Hi,

I wish to put a total AT THE BOTTOM of a list of numbers in a macro.
The list is variable length and I want to use the subtotal(109, function

as
there will be filters applied to the data and I only wish it to add items
displayed.

I tried this but it crashed on the last line. Help Please!!
LastRowNumber = Range("D65536").End(xlUp).Row
Moveup = LastRowNumber - 2
ActiveCell.SpecialCells(xlLastCell).Select
ActiveCell.Offset(1, -1).Range("A1").Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(109,R[-Moveup]C:R[-1]C)"





Chris G

Sum a Column of Variable length
 
that's clever ! I like it

Thanks

"Bob Phillips" wrote:

Try

LastRowNumber = Range("D" & Rows.Count).End(xlUp).Row
MoveUp = LastRowNumber - 2
Cells(LastRowNumber + 1, "D").FormulaR1C1 = "=SUBTOTAL(9,R[-" & MoveUp &
"]C:R[-1]C)"


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Chris G" wrote in message
...
Hi,

I wish to put a total AT THE BOTTOM of a list of numbers in a macro.
The list is variable length and I want to use the subtotal(109, function

as
there will be filters applied to the data and I only wish it to add items
displayed.

I tried this but it crashed on the last line. Help Please!!
LastRowNumber = Range("D65536").End(xlUp).Row
Moveup = LastRowNumber - 2
ActiveCell.SpecialCells(xlLastCell).Select
ActiveCell.Offset(1, -1).Range("A1").Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(109,R[-Moveup]C:R[-1]C)"






Bob Phillips

Sum a Column of Variable length
 
I had to do it that way as in my test data the last cell was in a completely
different column <G

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Chris G" wrote in message
...
that's clever ! I like it

Thanks

"Bob Phillips" wrote:

Try

LastRowNumber = Range("D" & Rows.Count).End(xlUp).Row
MoveUp = LastRowNumber - 2
Cells(LastRowNumber + 1, "D").FormulaR1C1 = "=SUBTOTAL(9,R[-" &

MoveUp &
"]C:R[-1]C)"


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Chris G" wrote in message
...
Hi,

I wish to put a total AT THE BOTTOM of a list of numbers in a macro.
The list is variable length and I want to use the subtotal(109,

function
as
there will be filters applied to the data and I only wish it to add

items
displayed.

I tried this but it crashed on the last line. Help Please!!
LastRowNumber = Range("D65536").End(xlUp).Row
Moveup = LastRowNumber - 2
ActiveCell.SpecialCells(xlLastCell).Select
ActiveCell.Offset(1, -1).Range("A1").Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(109,R[-Moveup]C:R[-1]C)"









All times are GMT +1. The time now is 03:17 PM.

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