rootdown42
Board Regular
- Joined
- Jun 8, 2005
- Messages
- 93
I have a workbook with multiple sheets that all have the same layout. I want to loop through those sheets and apply the Subtotal function to them. However, I'm struggling even to select the data to apply the Subtotals to. When the code to select the range is executed I get a run-time 1004 error for reasons I don't understand. There is nothing on any of these sheets that would prevent this range from being selected. If I execute the code while the active sheet equals the sheet selected in the array I don't receive the 1004 error, but nothing gets selected.
Can someone please help me understand what is incorrect about the way I'm selecting this range?
Code:
Dim iSheet As Worksheet
'Cycle through Summary sheets to add subtotals
For Each iSheet In Worksheets(Array("Qtr Summary", "Mo1 Summary", "Mo2 Summary", "Mo3 Summary", "YTD Summary"))
iSheet.Range("F7", iSheet.Range("F7").End(xlDown).End(xlToRight)).Select <---1004 Error occurs or nothing is selected
Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(5, 6, 7, 8, _
9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25), Replace:=False, _
PageBreaks:=False, SummaryBelowData:=True
Selection.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(5, 6, 7, 8, _
9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25), Replace:=False, _
PageBreaks:=False, SummaryBelowData:=True
Next iSheet