Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default Macro for Automatic Subtotals

Would like to create a macro that will auto subtotal a A/R Collection report.
The data is pulled externally then I subtotal the information. I created a
macro but the problem that I have is the rows change everyday. For example,
today the reports shows 1184 rows tomorrow it can show either more or less
than this number. If I run this macro with the rows not being 1184 the
output is not the same.

How do I create the macro to know that when the last line with data is the
ending range/row? Any comments would be greatly appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro for Automatic Subtotals

Can you pick out a column that always has data in it if the row is used?

I'm gonna use column A.

dim LastRow as long
dim myRng as range

with activesheet
lastrow = .cells(.rows.count,"A").end(xlup).row

'how many columns, I used Z:
set myrng = .range("A1:Z" & lastrow)
end with

myrng.subtotal....

NYbills wrote:

Would like to create a macro that will auto subtotal a A/R Collection report.
The data is pulled externally then I subtotal the information. I created a
macro but the problem that I have is the rows change everyday. For example,
today the reports shows 1184 rows tomorrow it can show either more or less
than this number. If I run this macro with the rows not being 1184 the
output is not the same.

How do I create the macro to know that when the last line with data is the
ending range/row? Any comments would be greatly appreciated.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default Macro for Automatic Subtotals

All data comes from the external source so there is no data that is always
there. Thanks for your input. The first answer resolved the issue.

"Dave Peterson" wrote:

Can you pick out a column that always has data in it if the row is used?

I'm gonna use column A.

dim LastRow as long
dim myRng as range

with activesheet
lastrow = .cells(.rows.count,"A").end(xlup).row

'how many columns, I used Z:
set myrng = .range("A1:Z" & lastrow)
end with

myrng.subtotal....

NYbills wrote:

Would like to create a macro that will auto subtotal a A/R Collection report.
The data is pulled externally then I subtotal the information. I created a
macro but the problem that I have is the rows change everyday. For example,
today the reports shows 1184 rows tomorrow it can show either more or less
than this number. If I run this macro with the rows not being 1184 the
output is not the same.

How do I create the macro to know that when the last line with data is the
ending range/row? Any comments would be greatly appreciated.


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 180
Default Macro for Automatic Subtotals

How do you select the range when recording your macro? If you manually
highlighted the data, then the range is hard-coded w/in the macro. The
easiest solution (assuming that other steps in the macro don't depend on the
number of rows), is to let Excel determine the range dynamically.
Ex:
I'm guessing that you've got something like
Range("A1:N269").Select
Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(14), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
Instead, select a specific starting point, and left Excel determing the
extents (the change is substituting the first three rows below for the first
row above):
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(14), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
--Bruce

"NYbills" wrote:

Would like to create a macro that will auto subtotal a A/R Collection report.
The data is pulled externally then I subtotal the information. I created a
macro but the problem that I have is the rows change everyday. For example,
today the reports shows 1184 rows tomorrow it can show either more or less
than this number. If I run this macro with the rows not being 1184 the
output is not the same.

How do I create the macro to know that when the last line with data is the
ending range/row? Any comments would be greatly appreciated.

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default Macro for Automatic Subtotals

Worked like a charm. Thanks.

"bpeltzer" wrote:

How do you select the range when recording your macro? If you manually
highlighted the data, then the range is hard-coded w/in the macro. The
easiest solution (assuming that other steps in the macro don't depend on the
number of rows), is to let Excel determine the range dynamically.
Ex:
I'm guessing that you've got something like
Range("A1:N269").Select
Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(14), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
Instead, select a specific starting point, and left Excel determing the
extents (the change is substituting the first three rows below for the first
row above):
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(14), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
--Bruce

"NYbills" wrote:

Would like to create a macro that will auto subtotal a A/R Collection report.
The data is pulled externally then I subtotal the information. I created a
macro but the problem that I have is the rows change everyday. For example,
today the reports shows 1184 rows tomorrow it can show either more or less
than this number. If I run this macro with the rows not being 1184 the
output is not the same.

How do I create the macro to know that when the last line with data is the
ending range/row? Any comments would be greatly appreciated.



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
Search, Copy, Paste Macro in Excel [email protected] Excel Worksheet Functions 0 January 3rd 06 06:51 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
macro with F9 Kenny Excel Discussion (Misc queries) 1 August 3rd 05 02:41 PM
Make Alignment options under format cells available as shortcut dforrest Excel Discussion (Misc queries) 1 July 14th 05 10:58 PM
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM


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