I have a report that is ran once a month and each sheet in the report has a variable number of rows each month. I have used the macro recorder to subtotal each sheet, but on sheets with more rows, the code does not include them in subtotal. I have tried using an offset but that didn't work either. Can someone help me determine what I can change so that the selected data will go to the last row with data before subtotaling?
Thank you for your help.
Code:
Range("A1:P6").Select
Range(Selection, Selection.End(xlDown)).Select
Range("A1:P364").Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$P$364"
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = "$1:$1"
.PrintTitleColumns = ""
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = "$A$1:$P$364"
Application.PrintCommunication = False
With ActiveSheet.PageSetup
[COLOR=#800080] (I deleted page setup details to make this code shorter and it works fine) [/COLOR]
End With
Application.PrintCommunication = True
Selection.Subtotal GroupBy:=6, Function:=xlCount, TotalList:=Array(7), _
Replace:=True, PageBreaks:=True, SummaryBelowData:=True
Range("F1").Select
Selection.End(xlDown).Select
Thank you for your help.