LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Help with using the SUBTOTAL formula in a macro.

I have written a macro that filters a range of data, then subtotals a
row of sales figures in that range using the =SUBTOTAL function. A
new set of sales figures comes out every week. But I am unable to
apply the same macro to the new sales figures because the number of
rows in the worksheet changes from week to week. The range in the
subtotal formula stays static while the numbers of rows is increased
or decreased each week. This causes the subtotal formula to only pick
up the range of data I originally asked for when I wrote the macro.

This is a copy of the macro…

Range("A1").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.AutoFilter
Rows("2:2").Select
ActiveWindow.FreezePanes = True
Columns("E:E").Select
Selection.Insert Shift:=xlToRight
Selection.ColumnWidth = 4
Range("D2").Select
Selection.End(xlDown).Select
Selection.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "D"
Selection.Copy
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Range("E2").Select
Selection.End(xlDown).Select

Selection.Offset(2, 2).Range("A1").Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-327]C:R[-2]C)"

So if I run the macro the next week and the sheet has more or less
than 327 rows the macro only subtotals from E2 to E327.

Does anyone know how I can make the range that I subtotal relative to
where the offset starts back to the top of the column?

Thanks in advance,

Steve M.
 
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
sort macro, subtotal and add lines after subtotal David Excel Discussion (Misc queries) 1 August 29th 09 10:56 AM
MACRO HELP WITH SUBTOTAL AND RANGES Gemi Excel Discussion (Misc queries) 2 August 20th 08 06:40 PM
Macro add row and subtotal simplymidori[_2_] Excel Discussion (Misc queries) 0 April 30th 08 12:34 AM
macro excel subtotal in subtotal GBO Excel Discussion (Misc queries) 2 November 29th 07 02:15 PM
Subtotal Macro [email protected] Excel Worksheet Functions 1 January 26th 05 11:13 AM


All times are GMT +1. The time now is 07:00 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"