Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using Subtotals in VBA


Hello,
I'm trying to sub-totals in macro where the last row will vary.
Currently I'm using the code that the Macro recorder recorded but it
doesn't work if there are more rows than what's in the macro. The
macro recorded:

ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[2]C:R[1068]C)"

I've tried ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-" & C3 &
"]C:R[-1]C)" but it doesn't return totals. My subtotals are at the top
of my columns - I don't if that makes a difference.

Please help. :


--
Lizz45ie
------------------------------------------------------------------------
Lizz45ie's Profile: http://www.excelforum.com/member.php...o&userid=23410
View this thread: http://www.excelforum.com/showthread...hreadid=482977

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Using Subtotals in VBA

Maybe

Dim iLastrow As Long

iLastrow = Cells(Rows.Count, ActiveCell.Column).End(xlUp).Row
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[2]C:R[" & iLastrow & "]C)"


--

HTH

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


"Lizz45ie" wrote in
message ...

Hello,
I'm trying to sub-totals in macro where the last row will vary.
Currently I'm using the code that the Macro recorder recorded but it
doesn't work if there are more rows than what's in the macro. The
macro recorded:

ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[2]C:R[1068]C)"

I've tried ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-" & C3 &
"]C:R[-1]C)" but it doesn't return totals. My subtotals are at the top
of my columns - I don't if that makes a difference.

Please help. :


--
Lizz45ie
------------------------------------------------------------------------
Lizz45ie's Profile:

http://www.excelforum.com/member.php...o&userid=23410
View this thread: http://www.excelforum.com/showthread...hreadid=482977



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Using Subtotals in VBA

Adds a list of numbers

Sub addsup()
Dim T As Object
Dim B As Object

Range("E3").Select
Set T = Selection
Selection.End(xlDown).Select
Set B = Selection
ActiveCell.Offset(1, 0).Select
Selection.Formula = "=sum(" & T.Address & ":" & B.Address & ")"

End Sub



"Lizz45ie" wrote:


Hello,
I'm trying to sub-totals in macro where the last row will vary.
Currently I'm using the code that the Macro recorder recorded but it
doesn't work if there are more rows than what's in the macro. The
macro recorded:

ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[2]C:R[1068]C)"

I've tried ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-" & C3 &
"]C:R[-1]C)" but it doesn't return totals. My subtotals are at the top
of my columns - I don't if that makes a difference.

Please help. :


--
Lizz45ie
------------------------------------------------------------------------
Lizz45ie's Profile: http://www.excelforum.com/member.php...o&userid=23410
View this thread: http://www.excelforum.com/showthread...hreadid=482977


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using Subtotals in VBA


Thanks Bob that worked. :)


--
Lizz45ie
------------------------------------------------------------------------
Lizz45ie's Profile: http://www.excelforum.com/member.php...o&userid=23410
View this thread: http://www.excelforum.com/showthread...hreadid=482977

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
Subtotals problem: Excel 2003 (not, AFAIK, the nested subtotals bug) AndyCotgreave Excel Discussion (Misc queries) 3 October 24th 07 11:32 AM
Original subtotals should not be within nested subtotals in excel Mirage Excel Worksheet Functions 1 June 6th 07 01:37 AM
How do I copy an outline w/ subtotals & paste just the subtotals av Excel Discussion (Misc queries) 1 June 20th 05 11:35 PM
Problem with nested subtotals, placing secondary subtotals BELOW . Dawn Cameron Excel Discussion (Misc queries) 1 June 3rd 05 10:13 PM
why are nested subtotals coming out below outer subtotals? Hendy Excel Worksheet Functions 2 January 18th 05 08:09 PM


All times are GMT +1. The time now is 06:19 AM.

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"