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: 24
Default Subtotal for same range of multiple worksheets

Hi,

I have a workbook where data is compiled through out the year and has to be
re-ran from the beginning of the year each month due to changes in open
orders. I also have worksheets breaking down each month, but it has become a
problem recreating the worksheets each month. I have code (from Ron de
Bruin) to create a worksheet for each month ("01-09", "02-09", etc.). Now, I
want to save the workbook (ActiveWorkbook.Save) after the pages are created
and run the following code for worksheets named 01-09, 02-09, etc. This will
work for one worksheet, but I can't seem to find the right code to make it
work for an array of worksheets.
It will sort and subtotal specified columns and then bold total rows and
insert a row after each total row.

Sub Total_Worksheets()

Dim rng As Range

Range("A1:p900").Select
Selection.Sort Key1:=Range("c2"), Order1:=xlAscending, _
Key2:=Range("A2"), Order2:=xlAscending, _
Key2:=Range("b2"), Order2:=xlAscending, _
Header:=xlYes

With Sheets("02-09")

On Error Resume Next
Set rng = Range(Range("j2"), Cells(2, Columns.Count).End(xlToLeft))
On Error GoTo 0
If Not rng Is Nothing Then

.Range("j2").Subtotal _
GroupBy:=3, _
Function:=xlSum, _
TotalList:=Array(10, 11, 12), _
Replace:=False, _
PageBreaks:=False, _
SummaryBelowData:=True

.Range("j2").Subtotal _
GroupBy:=1, _
Function:=xlSum, _
TotalList:=Array(10, 11, 12), _
Replace:=False, _
PageBreaks:=False, _
SummaryBelowData:=True

.Range("j2").Subtotal _
GroupBy:=2, _
Function:=xlSum, _
TotalList:=Array(10, 11, 12), _
Replace:=False, _
PageBreaks:=False, _
SummaryBelowData:=True

End If
End With

Dim LastRow As Long
Dim r As Long
LastRow = Range("G" & Rows.Count).End(xlUp).Row
For r = LastRow To 2 Step -1
If InStr(1, Cells(r, 1).Value, "Total") 0 Or _
InStr(1, Cells(r, 2).Value, "Total") 0 Or _
InStr(1, Cells(r, 3).Value, "Total") 0 Or _
InStr(1, Cells(r, 4).Value, "Total") 0 Then
Range(Cells(r, 1), Cells(r, 30)).Font.Bold = True
ActiveSheet.Rows(r + 1).EntireRow.Insert
End If
Next

End Sub

If this is possible to do over multiple sheets, I would really appreciate
code to make it work.
Thanks in advance,
Phisaw
 
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
Copying a range of data across multiple worksheets JLGWhiz Excel Programming 0 April 29th 09 06:12 PM
Copying a range of data across multiple worksheets Isaiah Melton Excel Programming 0 April 29th 09 05:26 PM
Sum same cell/range of multiple worksheets within a workbook... geld Excel Worksheet Functions 3 January 5th 07 05:15 AM
same named range on multiple worksheets? Philip Reece-Heal Excel Discussion (Misc queries) 4 June 1st 06 11:37 PM
range problem with multiple use of subtotal function Debra Dalgleish Excel Programming 1 April 1st 04 04:25 PM


All times are GMT +1. The time now is 03:39 AM.

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"