Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default insert formula in last cell

Hi - I would like to be able to subtotal a column of numbers using the
following formula:

=subtotal(9, C2:?) where ? is the last cell that contains data. I would like to
insert the formula in the cell below the last row of data.

The data to be summed are in reports that I download daily and where the number
of rows that contain data will vary. I've tried to figure out how to do this
with a macro, but I'm stumped. Any help is appreciated.

Cheers,

Angela



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default insert formula in last cell

Angela, This should do it for you:

Sub subtotal()
Dim end_data As Long
end_data = ActiveSheet.Cells(Rows.Count, "C").End(xlUp).Row
Range("C" & end_data + 1).Formula = "=SUBTOTAL(9,C2:C" & end_data & ")"
End Sub

Mike F
"J_Gold" wrote in message
...
Hi - I would like to be able to subtotal a column of numbers using the
following formula:

=subtotal(9, C2:?) where ? is the last cell that contains data. I would
like to insert the formula in the cell below the last row of data.

The data to be summed are in reports that I download daily and where the
number of rows that contain data will vary. I've tried to figure out how
to do this with a macro, but I'm stumped. Any help is appreciated.

Cheers,

Angela





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default insert formula in last cell

One way:

Range("C" & Rows.Count).End(xlUp).FormulaR1C1 = _
"=SUBTOTAL(9, R2C:R[-1]C)"

In article ,
"J_Gold" wrote:

Hi - I would like to be able to subtotal a column of numbers using the
following formula:

=subtotal(9, C2:?) where ? is the last cell that contains data. I would like
to
insert the formula in the cell below the last row of data.

The data to be summed are in reports that I download daily and where the
number
of rows that contain data will vary. I've tried to figure out how to do this
with a macro, but I'm stumped. Any help is appreciated.

Cheers,

Angela

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default insert formula in last cell

Hi Mike - thanks, works great!

Cheers,

Angela
"Mike Fogleman" wrote in message
...
Angela, This should do it for you:

Sub subtotal()
Dim end_data As Long
end_data = ActiveSheet.Cells(Rows.Count, "C").End(xlUp).Row
Range("C" & end_data + 1).Formula = "=SUBTOTAL(9,C2:C" & end_data & ")"
End Sub

Mike F
"J_Gold" wrote in message
...
Hi - I would like to be able to subtotal a column of numbers using the
following formula:

=subtotal(9, C2:?) where ? is the last cell that contains data. I would like
to insert the formula in the cell below the last row of data.

The data to be summed are in reports that I download daily and where the
number of rows that contain data will vary. I've tried to figure out how to
do this with a macro, but I'm stumped. Any help is appreciated.

Cheers,

Angela







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 691
Default insert formula in last cell

Hi Angela,
Implementing your formula would be half of the solution, so if you
would like to see how to invoke a subroutine to place a SUBTOTAL
at the end of the current column on a rightclick see
macro endtotal_sub implemented into your rightclick (context) menu in
Right Click Menus (Context Menus) in Excel
http://www.mvps.org/dmcritchie/excel/rightclick.htm

The macro itself would be

Sub EndTotal_sub()
Dim end_data As Long 'dmcritchie RClick 2005-05-28
Range(ActiveCell.Address, _
Cells(Rows.Count, ActiveCell.Column).End(xlUp).Address).Select
end_data = ActiveSheet.Cells(Rows.Count, ActiveCell.Column).End(xlUp).Row
ActiveSheet.Cells(end_data + 1, ActiveCell.Column).Formula = _
"=SUBTOTAL(9," & ActiveSheet.Cells(2, ActiveCell.Column).Address(1, 0) _
& ":OFFSET(" & ActiveSheet.Cells(end_data + 1, _
ActiveCell.Column).Address(0, 0) & ",-1,0))"
End Sub
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"J_Gold" wrote l...
Hi Mike - thanks, works great!

Cheers,

Angela
"Mike Fogleman" wrote in message
...
Angela, This should do it for you: [clipped]





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default insert formula in last cell

Hi David - Thanks! hadn't even thought of taking it that far - perfect
solution.

Cheers,

Angela


"David McRitchie" wrote in message
...
Hi Angela,
Implementing your formula would be half of the solution, so if you
would like to see how to invoke a subroutine to place a SUBTOTAL
at the end of the current column on a rightclick see
macro endtotal_sub implemented into your rightclick (context) menu in
Right Click Menus (Context Menus) in Excel
http://www.mvps.org/dmcritchie/excel/rightclick.htm

The macro itself would be

Sub EndTotal_sub()
Dim end_data As Long 'dmcritchie RClick 2005-05-28
Range(ActiveCell.Address, _
Cells(Rows.Count, ActiveCell.Column).End(xlUp).Address).Select
end_data = ActiveSheet.Cells(Rows.Count, ActiveCell.Column).End(xlUp).Row
ActiveSheet.Cells(end_data + 1, ActiveCell.Column).Formula = _
"=SUBTOTAL(9," & ActiveSheet.Cells(2, ActiveCell.Column).Address(1, 0) _
& ":OFFSET(" & ActiveSheet.Cells(end_data + 1, _
ActiveCell.Column).Address(0, 0) & ",-1,0))"
End Sub
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"J_Gold" wrote l...
Hi Mike - thanks, works great!

Cheers,

Angela
"Mike Fogleman" wrote in message
...
Angela, This should do it for you: [clipped]





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 691
Default insert formula in last cell

Hi Angela,
Glad to add something additional to help with Mike's solution.
I'm kind of partial to context menus as you might notice from
the related area at the bottom of that page for other applications
as well.
http://www.mvps.org/dmcritchie/excel/rightclick.htm

The reason for use of OFFSET is so that you can add or
delelet rows immediately before the total.
http://www.mvps.org/dmcritchie/excel/offset.htm
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"J_Gold" wrote...
Hi David - Thanks! hadn't even thought of taking it that far - perfect
solution. ---Cheers, Angela




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
Insert text from one cell into formula in another cell. Deserthawk99 Excel Discussion (Misc queries) 2 March 1st 08 05:02 PM
how do I insert a cell value in a hyperlink formula maijik New Users to Excel 1 December 18th 07 08:47 PM
Insert row adds formula to cell Johnny G Excel Discussion (Misc queries) 2 August 15th 07 06:10 PM
How do I insert a formula in a cell,which contains some text Smitha Roney Excel Discussion (Misc queries) 5 July 9th 07 01:26 PM
How to insert a complex formula in a cell with VBA mircea Excel Worksheet Functions 6 January 4th 05 08:12 PM


All times are GMT +1. The time now is 05:15 PM.

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

About Us

"It's about Microsoft Excel"