Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Insert text from one cell into formula in another cell. | Excel Discussion (Misc queries) | |||
how do I insert a cell value in a hyperlink formula | New Users to Excel | |||
Insert row adds formula to cell | Excel Discussion (Misc queries) | |||
How do I insert a formula in a cell,which contains some text | Excel Discussion (Misc queries) | |||
How to insert a complex formula in a cell with VBA | Excel Worksheet Functions |