Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Search, Copy, Paste Macro in Excel | Excel Worksheet Functions | |||
Closing File Error | Excel Discussion (Misc queries) | |||
macro with F9 | Excel Discussion (Misc queries) | |||
Make Alignment options under format cells available as shortcut | Excel Discussion (Misc queries) | |||
Playing a macro from another workbook | Excel Discussion (Misc queries) |